Graceful shutdown involves calling worker.disconnect() to stop accepting new connections, waiting for existing requests to finish, and then killing the process if needed. This prevents abrupt connection drops for active clients.
A graceful shutdown is important in production to avoid dropping in-flight requests. Instead of immediately killing a worker with worker.kill(), you first disconnect it so it stops accepting new connections, let it finish processing ongoing requests, and optionally force-kill it if it takes too long using a timeout.
Call worker.disconnect() — closes the IPC channel and stops accepting connections
Wait for the 'disconnect' event to confirm clean disconnection
Set a timeout (e.g., 5s) as a safety net to force-kill if requests hang
Call worker.kill() to forcefully terminate if disconnect timeout is exceeded
Perform cleanup in the worker: close DB connections, flush caches, finalize logs
You have a Node.js app using the cluster module with a single worker. How would you implement a graceful shutdown when the process receives SIGTERM?
What steps would you take to make sure the worker finishes any in‑flight HTTP requests before exiting?
If you call worker.disconnect() and immediately exit the master, what could happen to ongoing requests?
We noticed that after sending a SIGINT to our clustered server, some requests are being dropped. Walk me through how you'd debug the shutdown sequence and what changes you'd make.
Explain the trade‑offs between using worker.disconnect() versus worker.kill() in a production service that must meet an SLA during deployments.
Our monitoring shows workers sometimes hang after we call process.exit() in the master. How would you modify the shutdown logic to avoid this?
Design a shutdown protocol for a cluster of 20 workers handling long‑running jobs, ensuring no job is lost and the system can scale down gracefully under load spikes.
How would you coordinate graceful shutdown across multiple Node.js services that communicate via message queues, considering back‑pressure and message acknowledgment?
Discuss the performance impact of waiting for each worker's 'disconnect' event versus forcing termination after a timeout. When would you choose each approach?
Our platform is migrating from a monolithic Node.js app to microservices but still uses clustering for CPU scaling. How would you evolve the graceful shutdown strategy to support rolling upgrades across services while minimizing downtime and keeping compatibility with legacy workers?
At a company‑wide level we need a standardized shutdown framework for all Node.js services, some using cluster and others using worker_threads. What architectural guidelines would you propose, and how would you drive cross‑team adoption and backward compatibility?