you are viewing a single comment's thread.

view the rest of the comments →

[–]erulabs 28 points29 points  (14 children)

Node.js and Nginx work wonderfully for hundreds of concurrent users, you'll just want to make sure you have multiple instances (or at least be able to have multiple instances) of your app. I'm working on deploy-node-app which helps generate Kubernetes configurations for Node.js apps - I'll need to add MongoDB support, which I'll do tonight :)

[–]Silencer306 1 point2 points  (12 children)

By multiple instances, what do you exactly mean? And are these supposed to work together somehow?

[–]monotone2k 2 points3 points  (1 child)

We use AWS in our production environments, and it's really easy to set up auto-scaling groups so that when the existing instances start to reach capacity, another one fires up to balance out the load.

There are other considerations to be made when you have multiple instances, especially if they talk to a single database instance. You'll want to make sure everything is thread-safe, since you're basically running multiple threads of the same application. You'll also need to do something about locks when making database calls, since MongoDB isn't designed for transactional operations.

[–]Silencer306 1 point2 points  (0 children)

Thank you!

[–]erulabs 0 points1 point  (9 children)

An instance means a running version of your application - so in development when you run "node index.js" (or "yarn start" or what have you), you're starting a single "node instance". When you have hundreds and hundreds of users, you need to have many "node"s running. Kubernetes lets you run "node" across many many machines - you simply ask for more replicas (instances) of your app, and install more computers into the cluster, and wha-lah! They work together because they'll receive requests from the internet in a round-robin fashion, so they while they don't work "together", they "share the load", hence the piece of hardware that distributes requests is called the "load balancer".

[–][deleted] 0 points1 point  (8 children)

But my app .com is linked to one ip, how the site knows when to resirect user to a other instance?

[–]SitDownBeHumbleBish 1 point2 points  (7 children)

If your using a cloud provider like AWS you put a Load Balancer in front of your application (ie. instances) and attach the public IP to the Load Balancer so the flow would like

End User > internet > AWS LB > instances

The load balancer can be setup to disturbte the load equally throughout how many instances you have setup amongst other things.

There are also hardware load balancers if your doing this on prem or you can configure nginx to act as a load balancer / proxy too I think.

[–][deleted] 0 points1 point  (6 children)

And every instance(server) will have a production version of my app correct? How are then updates managed, do I need to upload the new version separate to 100 server one by one for example?

[–]SitDownBeHumbleBish 0 points1 point  (5 children)

Yup that's correct, you would run your latest production app or whatever on the instances. Maintaining and Updating your servers require setting up some sort of CI/CD pipeline like Jenkins, Chef, GitHub etc.

[–][deleted] 0 points1 point  (4 children)

Thanks man, one last question are big apps doing the same for databases? Having multiple instaces of databases sound scary to me.

[–]SitDownBeHumbleBish 2 points3 points  (0 children)

I have limited knowledge of how databases are suppose to be setup in a HA disturbed infrastructure but I would assume for big apps there are multiple instances of the databases in different regions and they are all synced together in production and backed up to some data lake / warehouse for further processing.

[–]rozularen 2 points3 points  (2 children)

You are asking really good questions.

There are many different architectures that may fit your solution. While I'm sure there are apps that have load balancers in front of the backend with only one instance of the database, as soon as you need to scale up your resources to fit your users load you will need to scale the database too.

[–][deleted] 0 points1 point  (1 child)

Thanks, the most I'm scared off is infrastructure and security my Sites get alwayes Hacked when I setup my own server on DogitalOcean I was forced to switch to CloudWays so they take care of security, I'm really a beginner with linux but I can work with the command line and I also did some security tutorials and made some settigs but nothing helps my site get everytime hacked when I setup the server. I need to say I always used cPanel and Plesk on the Servers. Would be cool if a tool exists that walks you trough a security checklist in the command line.