ALB Connection Handling and Timeouts
What you'll learn: How Application Load Balancers manage persistent connections and gracefully handle instances being removed from service.
The Core Idea
When an ALB sits between clients and your backend instances, it maintains two separate connections: one from the client to the ALB, and another from the ALB to the target. You need to control how long these connections stay open when idle, how long requests can run, and what happens when you're taking instances out of rotation.
Key Settings Explained
Idle Timeout is how long the ALB keeps a connection open when no data flows. Think of it like a phone line—if nobody talks for several minutes, should you hang up? The default is 60 seconds. If your application sends data infrequently (like long-polling or streaming), increase this value.
Connection Draining (also called deregistration delay) is the grace period given to in-flight requests when you remove an instance from the target group. Instead of abruptly cutting connections when you terminate an instance or deploy new code, the ALB stops sending new requests to that target but allows existing requests to complete. Default is 300 seconds; adjust based on your longest expected request duration.
Keep-Alive Settings control HTTP connection reuse between the ALB and your targets. If your backend supports keep-alive, the ALB reuses connections instead of opening new ones for each request, reducing latency and resource usage.
Practical Impact
Set your backend's keep-alive timeout longer than the ALB's idle timeout so the ALB closes idle connections first, preventing unexpected connection resets. During deployments, connection draining ensures zero downtime—users won't see errors mid-request when instances cycle.
Key Takeaway: Proper connection timeout and draining configuration ensures your ALB gracefully handles long-running requests and instance lifecycle events without dropping user traffic.