Connection draining is the process by which a load balancer stops sending new requests to a backend instance that is being taken out of service, while allowing existing, in-flight connections to complete naturally. This mechanism, also called deregistration delay, is essential for performing maintenance, deploying updates, or scaling down a fleet without abruptly terminating active user sessions or transactions. It prevents client errors and data corruption by giving ongoing requests time to finish processing.
Glossary
Connection Draining

What is Connection Draining?
Connection draining, also known as deregistration delay, is a critical process in load balancing for ensuring graceful service termination.
In a heterogeneous fleet orchestration context, such as managing mixed fleets of autonomous mobile robots and manual vehicles, connection draining principles apply to dynamic task allocation and agent decommissioning. The load balancer or orchestration middleware uses health checks to identify an instance for removal, initiates draining, and only fully terminates the instance after the configured delay or when all active connections close. This ensures zero-downtime deployments and maintains system reliability during fleet reconfiguration.
Key Features of Connection Draining
Connection draining, also known as deregistration delay, is a graceful termination process used by load balancers. It ensures operational stability by allowing in-flight requests to complete before a backend instance is fully removed from service.
Graceful Deregistration
Connection draining is the controlled process by which a load balancer marks a backend instance as deregistering or draining. The instance stops receiving new connections but continues to process all existing, active connections until they complete or a timeout is reached. This prevents abrupt termination of user sessions, file uploads, or database transactions, ensuring a seamless experience during deployments, scaling-in events, or instance maintenance.
- Core Mechanism: The load balancer's health check status for the instance changes from
healthytodraining. - Traffic Flow: New requests are routed to other healthy instances in the pool.
- Session Integrity: Long-lived connections like WebSockets or streaming sessions are allowed to conclude naturally.
Configurable Drain Timeout
The drain timeout (or deregistration delay) is a critical, user-defined parameter that sets a maximum duration for the draining process. It acts as a safety mechanism to prevent instances from hanging indefinitely due to stuck connections.
- Typical Range: Timeouts are configurable, often from 1 second to 3600 seconds (1 hour).
- Timeout Behavior: If active connections persist beyond the timeout, the load balancer forcibly terminates them and removes the instance.
- Use Case Tuning: A short timeout (e.g., 30s) is suitable for stateless APIs. Long-lived stateful services (e.g., video streaming) may require a timeout of several minutes.
- Example: AWS Elastic Load Balancing allows a deregistration delay configurable between 0 and 3600 seconds.
Integration with Deployment Strategies
Connection draining is a foundational enabler for modern, zero-downtime deployment methodologies. It works in concert with orchestration platforms to ensure service continuity during updates.
- Blue-Green Deployments: Draining allows the 'blue' (old) environment to gracefully finish requests while traffic is shifted entirely to the 'green' (new) environment.
- Canary Releases: When a canary instance (running new code) is deemed unhealthy and needs removal, draining ensures its active users are not abruptly disconnected.
- Auto-Scaling Scale-In: When a cloud auto-scaling group removes an instance to reduce capacity, connection draining is triggered to prevent dropped requests.
- Orchestration Handshake: Platforms like Kubernetes use a termination grace period which coordinates with the service mesh or ingress controller's draining logic.
Layer 4 vs. Layer 7 Draining Behavior
The implementation and granularity of connection draining differ significantly between Layer 4 (Transport) and Layer 7 (Application) load balancers, due to their fundamental operating models.
-
Layer 4 (TCP/UDP) Draining:
- Operates on connections. The load balancer stops establishing new TCP connections to the draining instance.
- Existing TCP connections remain open until closed by the client/server or the drain timeout expires.
- Less granular; cannot distinguish between different HTTP requests on the same persistent connection.
-
Layer 7 (HTTP/HTTPS) Draining:
- Operates on requests. The load balancer stops sending new HTTP requests to the draining instance.
- Can allow existing requests to complete while rejecting new ones on the same persistent HTTP connection.
- More intelligent, enabling true request-level graceful shutdown for HTTP/1.1 and HTTP/2.
Health Check Coordination
Connection draining requires careful coordination with the load balancer's health check system to avoid conflicting signals and ensure traffic is routed correctly during the drain phase.
- Dual Status: An instance has two logical statuses: its health state (healthy/unhealthy) and its registration state (registered/draining/deregistered).
- Failed Health Checks During Drain: If an instance fails a health check while draining, most systems will immediately terminate all connections and deregister the instance, overriding the drain timeout. This prevents a failing instance from prolonging its own shutdown.
- Proactive Draining Initiation: Draining is typically initiated by an external orchestration command (e.g., a deployment tool, scaling policy) rather than being triggered automatically by a failed health check.
Application-Level Draining Signals
For maximum gracefulness, applications should be designed to respond to draining signals from the infrastructure. This allows for in-memory state cleanup, final log flushing, and notification to upstream dependencies before the process terminates.
- SIGTERM Signal: In containerized environments (Docker, Kubernetes), the orchestrator sends a SIGTERM signal to the application process when a pod is scheduled for termination, initiating the drain phase.
- Application Responsibilities:
- Upon receiving SIGTERM, the app should stop accepting new work from its queue.
- Complete processing of current work items.
- Close listeners and database connections cleanly.
- Exit with code 0.
- Readiness Probes: Applications can expose a /health/ready endpoint that changes to an 'unready' status when draining begins, providing a signal to the load balancer or service mesh to stop sending traffic.
Connection Draining vs. Immediate Deregistration
Comparison of strategies for removing a backend instance from a load balancer's pool, focusing on request completion and client impact.
| Feature / Metric | Connection Draining | Immediate Deregistration |
|---|---|---|
Primary Objective | Gracefully complete in-flight requests | Fastest possible instance removal |
New Request Handling | Stops sending new requests immediately | Stops sending new requests immediately |
Existing Connection Handling | Allows active connections to complete naturally | Terminates all active connections abruptly |
Client Experience Impact | Zero failed requests for active sessions | All in-flight requests fail (TCP RST/connection error) |
Typical Use Case | Planned maintenance, deployments, scaling-in | Emergency failover, instance failure, security incident |
Deregistration Delay Configurable | Yes (e.g., 0 to 3600 seconds) | No (effectively 0 seconds) |
Load Balancer State During Process | Instance in 'draining' or 'deregistering' state | Instance removed from pool instantly |
Suitable for Stateful Sessions | Yes (preserves session completion) | No (causes session disruption) |
Frequently Asked Questions
Connection draining is a critical process for maintaining service availability during infrastructure updates. These questions address its core mechanisms, configuration, and role in modern orchestration.
Connection draining (also known as deregistration delay or graceful shutdown) is a load balancing process that stops sending new requests to a backend instance scheduled for removal while allowing existing, in-flight connections to complete naturally. It works by first marking the instance as draining or unhealthy for new traffic in the load balancer's routing table. The load balancer continues to honor and forward responses for requests already being processed by that instance but rejects or redirects any new connection attempts to other healthy instances in the pool. This ensures active sessions, such as file uploads, database transactions, or streaming responses, can finish without interruption before the instance is terminated or updated.
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
Connection draining is a critical component of graceful server lifecycle management within a load balancing system. Understanding these related concepts provides a complete picture of modern traffic distribution and high-availability architectures.
Health Check
A health check is a periodic, automated probe sent by a load balancer to backend servers to verify their operational status and readiness to accept traffic. It is the primary mechanism that triggers connection draining.
- Active Checks: The load balancer sends requests (e.g., HTTP GET, TCP SYN) to a predefined endpoint.
- Passive Checks: The load balancer monitors the success/failure rate of live client traffic.
- A failing health check initiates the deregistration process, often starting a connection draining period before the instance is fully removed from the pool.
Circuit Breaker Pattern
The circuit breaker pattern is a fault-tolerance design pattern that prevents an application from repeatedly attempting an operation that is likely to fail. It works in tandem with connection draining at the application logic layer.
- States: Closed (normal operation), Open (requests fail fast), Half-Open (testing for recovery).
- When a backend service exhibits failures, the circuit breaker trips to 'Open', rejecting new requests immediately—similar to a load balancer stopping new connections during draining.
- This pattern protects the overall system from cascading failures while existing in-flight transactions (like those being drained) can complete or time out.
Blue-Green Deployment
Blue-green deployment is a release strategy that reduces downtime and risk by maintaining two identical production environments. Connection draining is essential for executing clean traffic transitions between them.
- Only one environment (e.g., Blue) receives live production traffic.
- The new version is deployed to the idle environment (Green).
- After validation, the load balancer's routing is updated to point to Green. The Blue environment then undergoes connection draining, allowing existing sessions to complete before being taken offline for the next update cycle.
- This enables instant rollback by simply routing traffic back to the previous environment.
Canary Deployment
Canary deployment is a incremental release technique where a new version is rolled out to a small subset of users before a full launch. It uses fine-grained traffic shifting, which relies on controlled connection draining on the canary subset.
- A small percentage of traffic (e.g., 5%) is routed to the new canary instances.
- Metrics (error rates, latency) are closely monitored.
- If the canary is healthy, traffic is gradually shifted in larger increments (e.g., 25%, 50%, 100%).
- At each stage, the older version's instances undergo connection draining as they are progressively removed from the serving pool, ensuring no active user sessions are abruptly terminated.
Service Discovery
Service discovery is the automatic detection of network locations for service instances. Dynamic registration and deregistration of instances necessitate graceful shutdown procedures like connection draining.
- Client-Side Discovery: The client queries a service registry (e.g., Consul, Eureka) to find available instances.
- Server-Side Discovery: A load balancer queries the registry and routes requests on behalf of the client.
- When an instance shuts down, it must first deregister from the service registry. A deregistration delay (connection draining period) is often configured, allowing the registry to stop advertising the instance while it finishes processing its existing workload.
Session Persistence (Sticky Sessions)
Session persistence, or sticky sessions, is a method where a load balancer directs all requests from a user session to the same backend server. This creates a direct dependency that makes connection draining crucial.
- Implemented via cookies or source IP hashing.
- Without draining, removing a server for maintenance would forcefully terminate all active, stateful sessions for users stuck to that server, causing a poor user experience.
- Connection draining allows these stateful sessions to naturally complete on their designated server before it is terminated, preserving session state and user transactions.

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us