Load balancing with Express Js #4610
Replies: 3 comments
-
Hey @fjariwala, it looks like in order to integrate Express in those example - you just need to replace |
Beta Was this translation helpful? Give feedback.
-
What cluster mode does is spawn your application into multiple instances. It is helpful when your machine has multiple CPU cores.
PM2 will do a local load balancing for you. On the other hand, Nginx is a reverse proxy and handles things like caching, request routing etc for you. To add load balancing, you can add several upstreams to your reverse proxy configuration. Nginx will do the rest. As seen below There are other methods of doing that e.g Digital ocean has a load balancer as a service. |
Beta Was this translation helpful? Give feedback.
-
You're better off using something more performant for load balancing, either nginx or ideally a hardware load balancer based service like AWS ELB provides. As much as I love node/express for dynamic server content, it's not suited to doing load balancing or rate limiting |
Beta Was this translation helpful? Give feedback.
-
Recently, I was reading a blog about load balancing with NodeJs applications. And I was wondering if there are any possible ways available to load balance our Express Application, so I used PM2 "https://pm2.keymetrics.io/docs/usage/cluster-mode/" for my application.
If you would spend some time reading this blog, you will see that PM2 uses Cluster-Mode, which is slow in performance compared to iptables and nginx according to the blog "https://medium.com/@fermads/node-js-process-load-balancing-comparing-cluster-iptables-and-nginx-6746aaf38272".
Now my question is, can anybody help me integrate one of these load balancers into my Express application?
Beta Was this translation helpful? Give feedback.
All reactions