WebSocket Ingress Patterns
Long connections.
Overview
WebSocket ingress runs long-lived bidirectional connections through load balancers built primarily for short HTTP requests. Naive LB settings break WebSocket connections at the idle timeout; sticky sessions are needed for stateful workloads; rolling deploys require graceful drain so reconnections do not cascade. Real-time applications stand or fall on getting these settings right.
- Long connections. Connections last hours to days. Default HTTP timeouts are wrong by orders of magnitude.
- Idle timeout. LB idle timeout must exceed application heartbeat interval, or connections close prematurely.
- Sticky sessions. Same client routes to same backend across reconnects. Stateful workloads need this.
- HTTP/1.1 Upgrade plus health-aware draining. The handshake is HTTP; the connection lifecycle is not. Graceful connection close on backend removal supports rolling deploys.
The approach
Three habits make WebSocket ingress reliable: generous idle timeout that exceeds the application heartbeat, sticky sessions for stateful workloads, graceful drain on backend removal during deploys.
- Generous idle timeout. ALB default 60s; raise to 4 hours for typical WebSocket lifetimes.
- Application heartbeat. Ping every 30s. Catches dead connections without keeping LB timeouts artificially low.
- Sticky sessions. Cookie-based stickiness for stateful workloads. Reconnects land on the same backend.
- Graceful drain plus documented timeouts. Clean close on backend removal during deploys; per-tier the WebSocket settings documented.
Why this compounds
Each correctly-configured WebSocket ingress produces stable connections across deploys and scaling events. The team’s real-time application fluency deepens; reconnection storms stop being part of every deploy.
- Connection stability. Right timeouts produce stable connections. Users stop seeing reconnect spinners.
- Release safety. Graceful drain produces clean deploys. Reconnection storms shrink.
- Resilience. Heartbeats catch dead connections. Server-side resource cleanup follows.
- Year-one investment, year-two habit. First deployment is heavy lift. By the third, the WebSocket template is settled.