NLB Connection Handling
What you'll learn: How Network Load Balancers maintain and route TCP connections reliably using flow hash algorithms.
When a client connects to an NLB, something important happens: the load balancer needs to ensure all packets in that conversation go to the same backend server. This is called connection persistence and it's critical for Layer 4 protocols like TCP.
How Flow Hash Works
An NLB uses a flow hash algorithm to route connections consistently. It creates a unique "fingerprint" from:
- Source IP address
- Source port
- Destination IP address
- Destination port
- Protocol type (TCP/UDP)
Think of it like a sorting system at a post office: letters with the same return address and destination always go down the same chute. The NLB calculates this hash once per new connection, picks a target, and remembers that mapping for the connection's lifetime.
Connection Lifecycle
Unlike Application Load Balancers (which terminate connections), NLBs pass connections through more directly:
- New connection arrives → NLB calculates flow hash
- Hash selects target → Connection forwarded to specific backend server
- All subsequent packets in that TCP flow follow the same path
- Connection persists until either side closes it
This means a single long-lived TCP connection (like a database connection) always talks to the same target, even if new connections are being distributed elsewhere.
Why This Matters
Flow hash ensures session consistency without requiring the NLB to inspect application data. It's ultra-fast and preserves the original client IP address, making it perfect for protocols that need true connection-level persistence (gaming servers, financial trading platforms, persistent database connections).
Key Takeaway: NLBs use flow hash algorithms based on connection 5-tuple (source IP, port, destination IP, port, protocol) to ensure all packets in a TCP connection consistently route to the same target throughout the connection's lifetime.