Connection Draining Patterns
Graceful LB removal.
Overview
Connection draining is what makes deploys zero-downtime. Backends remove themselves from the load balancer cleanly, in-flight requests complete, then the process exits. Without it, every deploy drops a slice of requests and customers see the difference. With it, deploys become invisible.
- Graceful LB removal. In-flight requests complete before the backend stops accepting new ones. Zero-error deploys.
- Drain timeout. How long to wait for in-flight to complete. Matches the longest expected request duration.
- Health check status. Backend reports unhealthy to start the drain. Load balancers stop sending new traffic; existing traffic completes.
- SIGTERM handling plus long-connection close. Application catches SIGTERM and finishes gracefully; WebSocket and gRPC streams need explicit close handshakes.
The approach
Three habits make connection draining real rather than theoretical: health-check-driven drain, drain timeout tuned to actual request profile, and SIGTERM handlers that stop accepting new work while finishing in-flight requests.
- Health check drives drain. Backend reports unhealthy before process exit. Load balancer stops sending new traffic immediately.
- Drain timeout tuned to longest expected request. Avoids the cutoff that drops in-flight requests.
- SIGTERM handler. Application stops accepting new connections, finishes existing ones, then exits. Standard Kubernetes pattern.
- Long-connection explicit close plus documented policy. WebSocket and gRPC explicit close handshakes; per-service the drain timeout documented.
Why this compounds
Each clean deploy preserves user experience that bad deploys would have damaged. The team’s deploy hygiene deepens; new services inherit the drain conventions instead of recreating them through customer-impact incidents.
- User experience preserved. Zero-error deploys keep trust intact across hundreds of releases.
- Release safety improves. Clean deploys reduce incident rate. Velocity rises.
- Operational maturity. Drain patterns scale to every service. The estate operates the same way.
- Year-one investment, year-two habit. First service takes care. By the third, drain handlers are part of the deploy template.