Blog
Graceful Shutdown Is A Deadline, Not A Courtesy
A process receives a termination signal. It has seconds to stop accepting work, finish what it owns, and leave state recoverable. That sequence is a protocol.
Drain In The Right Order
First fail readiness so load balancers stop assigning new traffic. Keep liveness healthy while draining; otherwise the platform may kill the process that is trying to finish safely.
Then stop accepting new requests and message fetches. Allow in-flight work to complete within a budget shorter than the platform’s termination deadline. Close pools and flush telemetry last.
Assume The Deadline Wins
Some work will not finish. HTTP clients may disconnect. A queue handler may lose its lease. A batch may be halfway through. Design operations to retry safely and commit ownership only after durable completion.
Do not sleep for an arbitrary delay and call that draining. Expose active requests, in-flight messages, and shutdown phase so tests can assert the sequence.
Test slow requests, stuck dependencies, repeated termination, and a forced kill. Ensure deploy tooling waits for old instances to leave before declaring success.
Graceful shutdown cannot promise every instruction completes. It promises the system stops taking new obligations, honors a clear deadline, and leaves unfinished obligations recoverable.