Graceful Shutdown
Graceful shutdown stops accepting new requests after receiving a termination signal, finishes in-flight requests, then exits, avoiding interrupted requests.
Purpose
Ensure no in-flight requests are lost during shutdown, enabling zero-downtime deployments.
Mechanism
On SIGTERM: 1) deregister from the load balancer (stop new requests); 2) wait for in-flight requests to finish (within a timeout); 3) close database connections; 4) exit. K8s preStop hook + terminationGracePeriodSeconds.
Use cases
- Zero-downtime deployment
- Request integrity
- K8s operations