node.jsexpressproductionhydra-core

Node.js project to production with a lot of traffic


I started a project and I started to have a lot of web traffic, and at some point I felt insecure of how to scale the project to production in two issues:

  1. How to perform updates without leaving my users without service?
  2. How to correctly configure Node.js so that it consumes less memory?

I have microservices working with Hydra-express, and I have not been able to implement Hydra-router and I do it with Express.js; I also have NGINX as a proxy gateway.

I am programming in ES6, transpiling with BABEL and maintaining active microservices with PM2, some with fork and the most important in cluster mode.

I was thinking about using docker, but I have not found any tutorial on how to use it with CDN, upload files and serve them to the user.


Solution

  • Adding to @ralphtheninja answer, I suggest you reading more about blue green deployments, as proposed by Martin Fowler; https://martinfowler.com/bliki/BlueGreenDeployment.html

    One of the challenges with automating deployment is the cut-over itself, taking software from the final stage of testing to live production. You usually need to do this quickly in order to minimize downtime. The blue-green deployment approach does this by ensuring you have two production environments, as identical as possible. At any time one of them, let's say blue for the example, is live. As you prepare a new release of your software you do your final stage of testing in the green environment. Once the software is working in the green environment, you switch the router so that all incoming requests go to the green environment - the blue one is now idle.

    Blue-green deployment also gives you a rapid way to rollback - if anything goes wrong you switch the router back to your blue environment.

    I have no idea where your backend is running but there are some services that will do it for you, AWS ElasticBeanstalk for example will put your instances behind a load balancer and will manage deployment according to a policy. have a look; https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/using-features.rolling-version-deploy.html.