Course contentsShow
← System Design
Lesson 109 of 1,9193. Load BalancingFree lesson

Layer 4 (Transport) Load Balancing

Understand TCP/UDP-level load balancing that routes based on IP and port without inspecting application data.

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:

  1. Receives the TCP/UDP packet
  2. Reads the IP addresses and port numbers
  3. Applies a load balancing algorithm (round robin, least connections, etc.)
  4. Forwards the packet to a selected backend server
  5. 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.