Node.js › Clustering & Worker Threads

How does zero-downtime restart work with Node's cluster module or PM2, and why is it important for production deployments?

Advanced

Answer

Zero-downtime restart replaces workers one at a time -- each old worker finishes in-flight requests and stops accepting new ones while a new worker starts, so at every point some workers remain available, meaning no dropped requests during a deployment.
pm2 reload my-app
// PM2 starts a new worker, waits for it to be ready, then gracefully
// shuts down one old worker at a time until all run the new code
Real-world example An e-commerce API deploys several times daily using 'pm2 reload' rather than 'pm2 restart', so customers mid-checkout never experience a dropped connection during routine deployments.

Common follow-ups: What's the difference between 'pm2 restart' and 'pm2 reload' regarding downtime?;How long should a worker be given to drain requests before forced termination during a reload?