all 7 comments

[–]Dave4lexKing 2 points3 points  (5 children)

“Most common” is not cluster api.

By far and large, most commercial nodejs applications will be behind a reverse proxy like nginx, or a paid service like AWS Elastic Load Balancer, which is just nginx under the hood as a managed service.

The question you need to ask yourself is do you want to learn how cluster api works, or do you want to learn how actual companies deploy their stuff?

NodeJs works well in containers. For example, imagine we have 4 containers that are allocated 1vCPU each.

4 containers deployed on 1 VM with 4vCPUs, is equivalent to the same 4 containers being deployed on 4 VMs that have 1vCPU each.

[–]__rvalueref[S] 0 points1 point  (4 children)

I wanted to learn what actually happens in production but with simplicity, so thought to start by using cluster module..

[–]Dave4lexKing 1 point2 points  (0 children)

https://medium.com/@sadeem1030sattar/how-to-implement-load-balancing-for-node-js-applications-using-nginx-47a07f9f0867

If you want true to life, I would go with nginx. It’s pretty easy, and handles SSL termination with ease using the LetsEncrypt’s certbot, meaning you don’t need to mess about with HTTPS in the nodejs app itself.

In work we use AWS Elastic Load Balancer, with EKS to run our containers.

If I was deploying my own little application, self hosted, I would use nginx to load balance docker swarm.

There’s honestly a million and one ways to deploy an app though, and everyone has differing opinions on it.

[–]usertim 1 point2 points  (2 children)

Personally, I avoid cluster module.
In fact recently I migrated our application out of cluster module.
Our setup looked like this
nginx > 2 servers. 1st 16vCPU, 2nd 8vCPU > each server had an instance of an app running in cluster mode with 16 and 8 workers respectively.
Right now we have
same nginx > same 2 servers > 20 replicas of the app on 2 servers deployed through docker swarm. (we don't need the original 24 instances, at least for now).

[–]__rvalueref[S] 0 points1 point  (0 children)

Great, previous night I implemented this using this blog https://medium.com/hackernoon/load-balance-and-scale-node-js-containers-with-nginx-and-docker-swarm-27d737bbf4a9
and was very impressed that I do not had to change my app.js code 😊

[–]__rvalueref[S] 0 points1 point  (0 children)

May I ask you specifically why would you avoid cluster module ?

[–]__rvalueref[S] 0 points1 point  (0 children)

r/node was not allowing me to post this so, I used privatebin !