Scalingdrainingderegistration delaygraceful shutdown

Connection draining

Definition

Connection draining marks an instance as leaving, so the load balancer sends it no new requests, and waits up to a timeout for existing requests and connections to complete before the instance shuts down.

In practice

Without draining, scale-in, rolling deploys and spot reclaims kill requests mid-flight and users see 502 errors. With it, the balancer deregisters the target, the application stops accepting new work on SIGTERM, finishes what it has and then exits. Kubernetes models this with a termination grace period and readiness probes that fail first.

The drain timeout is a trade-off: too short and long requests are cut off, too long and scale-in and deploys become slow. Long-lived connections such as WebSockets never finish on their own, so servers must close them and let clients reconnect elsewhere, ideally spread over time to avoid a reconnect storm.

Example

On scale-in, the balancer stops routing to the instance and waits up to 30 seconds; its 12 in-flight uploads finish in 8 seconds, then the instance terminates with no failed requests.