Layer 4 (Transport) Load Balancing
What You'll Learn
You'll understand how Layer 4 load balancers route traffic based on network information (IP addresses and ports) without looking at the actual application content.
The Core Idea
Layer 4 refers to the Transport Layer of the OSI networking model—where TCP and UDP protocols operate. A Layer 4 load balancer makes routing decisions using only information available at this layer: source IP, destination IP, source port, and destination port.
Crucially, it never inspects the application data itself. It doesn't know whether you're sending an HTTP request, a database query, or streaming video—it simply sees network packets and forwards them based on IP/port combinations.
How It Works
Think of a Layer 4 load balancer as a postal sorting facility that only reads the envelope. It sees the "from" and "to" addresses (IPs and ports) and routes packages accordingly, but never opens them to see what's inside.
When a client connects, the load balancer:
- Receives the TCP/UDP packet
- Reads the IP addresses and port numbers
- Applies a load balancing algorithm (round robin, least connections, etc.)
- Forwards the packet to a selected backend server
- Maintains that connection mapping for the duration of the session
Key Characteristics
- Fast: Minimal processing since it doesn't parse application protocols
- Protocol-agnostic: Works with any TCP/UDP traffic (HTTP, HTTPS, FTP, databases, gaming)
- Simple: Less complex than Layer 7, easier to configure
- Limited intelligence: Cannot route based on URLs, headers, or content
Key Takeaway: Layer 4 load balancing operates at the network transport level, routing traffic quickly based solely on IP addresses and ports without understanding the application data, making it faster but less flexible than application-aware alternatives.