Zero-Downtime Restart

Learn how to implement zero-downtime restart for a scalable Node.js application.

A Node.js application might also need to be restarted when we want to release a new version to our production servers. So, in this scenario as well, having multiple instances can help maintain the availability of our application.

When we have to intentionally restart an application to update it, there’s a small window in which the application restarts and is unable to serve requests. This can be acceptable if we’re updating our personal blog, but it’s not even an option for a professional application with a service-level agreement (SLA) or one that’s updated very often as part of a continuous delivery process. The solution is to implement a zero-downtime restart, where the code of an application is updated without affecting its availability.

Implementing a zero-downtime restart

With the cluster module, this is, again, a really easy task: the pattern involves restarting the workers one at a time. This way, the remaining workers can continue to operate and maintain the services of the application available.

Let’s add this new feature to our clustered server. All we have to do is add some new code to be executed by the primary process.

Get hands-on with 1200+ tech skills courses.