← Back to notes
Evergreen 2 min read

Notes on... Layer 4 vs Layer 7 Load Balancing (and the OSI Model)


When cloud docs (like Azure’s) talk about Layer 4 or Layer 7, they’re referring to the OSI model — a conceptual way to understand how networks work, split into 7 layers.

Here are the essentials.

The 7 Layers

  1. Physical (L1) — cables, signals
  2. Data Link (L2) — MAC addresses, switches
  3. Network (L3) — IP addresses, routing
  4. Transport (L4) — TCP/UDP, ports
  5. Session (L5) — connections between systems
  6. Presentation (L6) — encryption, formatting
  7. Application (L7) — HTTP, APIs, user-level data

In practice, developers mostly care about L4 and L7.

Layer 4 Load Balancing (Transport level)

  • Works with IP + Port
  • Doesn’t look inside the request
  • Fast and efficient

At this level, decisions are made purely based on network information like source/destination IP and port, without understanding the actual data being sent. This makes L4 load balancers extremely fast and scalable, but also “blind” to application logic — they can’t differentiate between different URLs or users, only connections.

Example: Incoming traffic on :443 → distribute between servers

Use cases:

  • High-performance systems
  • Simple traffic distribution
  • Non-HTTP protocols

Layer 7 Load Balancing (Application level)

  • Understands HTTP/HTTPS
  • Can inspect:
    • URLs (/api, /images)
    • Headers
    • Cookies

At this level, the load balancer understands the actual content of requests and can make intelligent routing decisions based on application-specific data. This enables fine-grained control like routing by endpoint, user session, or even modifying requests/responses, but comes with slightly higher latency and complexity.

Example:

  • /api/* → Backend A
  • /static/* → Backend B

Use cases:

  • Web apps and APIs
  • Microservices routing
  • Advanced rules (authentication, redirects, caching)

Azure Mapping (quick reference)

  • Layer 4 → Azure Load Balancer
  • Layer 7 → Azure Application Gateway, Azure Front Door

Mental model

  • Layer 4 = “Where should this packet go?”
  • Layer 7 = “What is this request asking for?”

Or:

L4 = sort by address
L7 = read the content and decide

Final note

Most modern systems use a combination of both: L4 for raw performance and connection handling, and L7 for smart routing and application-level control.