PM2: Zero-Downtime Reloads in Cluster Mode

PM2's reload command updates a clustered Node.js app without downtime by restarting processes one by one. Use this for live deployments. The footgun is using it on a stateful app, which will cause data loss unless state is externalized.
Why it exists
When you deploy new code, you need to restart your application server. A naive restart kills the old process and starts a new one, creating a window of downtime where user requests fail. For high-availability systems, even a few seconds of downtime is unacceptable, necessitating a way to update code without interrupting service.
The mental model
Think of pm2 reload as a rolling update for your server fleet, even if that fleet is just multiple processes on a single machine. Instead of shutting down the entire factory to retool, you update one assembly line at a time while the others keep running. In contrast, pm2 restart is the equivalent of a full factory shutdown.
How it works
PM2's cluster mode runs multiple instances of your Node.js app, typically one per CPU core, and load balances traffic between them. When you run pm2 reload <app_name>, PM2 sends a shutdown signal to one process. If the app is configured for graceful shutdown, it finishes its current requests and then exits. Once it's offline, PM2 starts a new process with the updated code. It repeats this cycle for every process, one by one, ensuring at least one process is always available. If a process fails to reload within a timeout, PM2 falls back to a standard restart.
When to use it
Use reload as your default deployment command for any production Node.js application managed by PM2 in cluster mode. It's designed specifically for updating code on live servers without interrupting service. You enable cluster mode with pm2 start app.js -i max or by setting instances: 'max' in your ecosystem file.
When not to use it
Do not use reload if your application is not running in cluster mode. More importantly, do not use it if your application stores state in its process memory, such as user sessions or active websocket connections. This state will be lost when the process restarts. You must first refactor your app to store shared state externally (e.g., in Redis) before you can safely use reload. Also, if your app doesn't handle graceful shutdown, you risk terminating requests mid-flight.
One canonical example
You have a Node.js Express API running on a 4-core server, started with pm2 start api.js -i max. After pushing new code, you run pm2 reload api. PM2 will gracefully shut down process 1, start a new process 1 with the new code, then move on to do the same for processes 2, 3, and 4 sequentially. Throughout this entire sequence, your API remains online.
Interview question
To avoid data loss or unexpected behavior when using pm2 reload, which application characteristic is most crucial to address?
- a.Its ability to handle a sudden increase in incoming traffic.
- b.Its reliance on in-memory storage for user sessions or active connections.Correct
- c.Its capacity to complete all current requests before shutting down.
- d.Its configuration to run in a single-instance (fork) mode.
Why? this is the answer
The card explicitly warns that if an application stores state in its process memory (e.g., user sessions), this state will be lost during a reload. Externalizing state is crucial to prevent data loss. While graceful shutdown (Option C) is important for preventing mid-flight request termination, it primarily addresses service disruption, not the loss of persistent application state.
Just read this? Test yourself on what you have been reading.
Read the original → pm2.io
You just looked this up. Could you explain it out loud?
That is the part interviews actually test. Tezvyn takes questions like this one and gives you what the interviewer is really checking, the answer that lands, and the mistake that ends the conversation, in the four minutes before your next meeting.
The iPhone app is on the way
We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.
Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.
We are hiring for this. Open roles that interview on nodejs — each one lists the topics its interview covers.
See open roles