Node.js Graceful Shutdown in Production: SIGTERM, In-Flight Draining, and Zero-Downtime Deploys
Node.js Graceful Shutdown in Production: SIGTERM, In-Flight Draining, and Zero-Downtime Deploys Your deployment pipeline fires. Kubernetes sends SIGTERM. Your Node.js process has 47 in-flight HTTP ...

Source: DEV Community
Node.js Graceful Shutdown in Production: SIGTERM, In-Flight Draining, and Zero-Downtime Deploys Your deployment pipeline fires. Kubernetes sends SIGTERM. Your Node.js process has 47 in-flight HTTP requests, 3 BullMQ jobs mid-execution, and a PostgreSQL connection pool with 8 active transactions. What happens next? If you haven't explicitly handled shutdown, the answer is: those requests die, those jobs fail, and your users see 502 errors during every deploy. In 2026, with rolling deployments, canary releases, and sub-second restart cycles, graceful shutdown is not optional — it's the difference between a professional service and a brittle one. This guide covers the complete graceful shutdown lifecycle for production Node.js services: signal handling, in-flight HTTP request draining, database cleanup, job queue flushing, and Kubernetes preStop hook integration. Why Shutdown Fails Without Explicit Handling Node.js exits on unhandled SIGTERM with an immediate kill — no cleanup, no drainin