Zero downtime deployment Nodejs application

2019-05-30 08:27发布

I have a Nodejs application that included clustering for being uptime and domain for error handling.

Now for achieving zero downtime deployment, I have an instruction but I need help to convert this instruction to Nodejs code (I need an example for it please).

This is the instruction:

  1. When master starts, give it a symlink to worker code.
  2. After deploying new code, update symlink
  3. Send a signal to master: fork new workers!
  4. Mater tells old workers to shut down, forks new workers from new code.
  5. Mater process never stop running

Instruction source -> slide number 39

1条回答
祖国的老花朵
2楼-- · 2019-05-30 08:53

For 100% uptime the road is more or less the same regardless of the language you are using:

  • Store your session tokens in a database rather than in an in-memory array or something. This will allow users to stay logged-in after you swap versions.

  • Run your server inside a Docker container

  • Use a proxy to handle swapping containers when you need to run a new server version.

I wrote easy-deploy to handle exactly that, so that I wouldn't need to worry about setting up the proxy every time.

Deploy version 1

easy-deploy -p 80:80 -v some/path:other/path my-image:1

To deploy a new version just run the command with the updated tag name

easy-deploy -p 80:80 -v some/path:other/path my-image:2

The proxy is taken care of. my-image:1 will be replaced by my-image:2 without letting any request drop.

查看更多
登录 后发表回答