Course contentsShow
← Node.js
Lesson 1469 of 1,98013. Error Handling and Resilient SystemsFree lesson

Zero-Downtime Deployment Patterns

You will utilize rolling deployments to ensure that new error-handling logic is deployed without interrupting service.

In this lesson, you will learn how to use rolling deployments to safely transition your Node.js application to new error-handling logic without dropping a single user request.

The Problem: The "Big Bang" Deployment

In a standard deployment, stopping your entire server pool to deploy new code creates a gap where requests fail. When we are updating critical error-handling logic—such as a new circuit breaker configuration or an improved logging integration—this gap is unacceptable. We need a way to swap out old instances for new ones incrementally.

The Strategy: Rolling Deployments

A rolling deployment replaces your application instances one by one. By leveraging your existing Readiness Probes (from Lesson 14), the load balancer only routes traffic to a new instance once it has fully booted and passed its internal health checks.

Imagine you have three replicas of your Node.js service. The strategy looks like this:

  1. Provision: Spin up a new pod with the updated error-handling logic.
  2. Readiness: The load balancer waits for the GET /health endpoint to return 200 OK.
  3. Shift: Traffic is sent to the new instance.
  4. Terminate: The oldest instance is shut down gracefully.

By using process.on('SIGTERM'), you ensure that the instance being replaced stops accepting new requests while finishing existing ones:

process.on('SIGTERM', () => {
  server.close(() => {
    console.log('Finished pending requests. Shutting down.');
    process.exit(0);
  });
});

Why this matters for Error Handling

When you deploy complex resilient features like predictive failure analysis or rate limiting updates, you aren't just changing code; you are changing the state of your system's defenses. If a new error handler contains a subtle bug, a rolling deployment allows you to catch it on the first instance before it affects the entire fleet. If your monitoring detects a spike in 5xx errors during the "roll," you can instantly halt the deployment. This incremental approach ensures that your system’s resilience logic is always active, even while it is evolving.

Key Takeaway: Use rolling deployments combined with graceful connection draining to ensure your error-handling logic evolves without creating service outages.