Back to roadmap
Module 4 · Edge: DNS, CDN, Load BalancersDay 03520 min

L4 vs L7 Load Balancing

Bytes and ports vs URLs and headers.

Day 035

L4 vs L7 Load Balancing

User
client
L4 LB
edge
L7 LB
edge
Services
service
Signal path
Layered L4 → L7 design
User
client
flow
L4 LB
edge
L4 LB
edge
flow
L7 LB
edge
L7 LB
edge
flow
Services
service
Memory hook

L4 vs L7 Load Balancing: bytes and ports vs urls and headers

Mental model

move the first decision closer to the user

Design lens

L4 is cheaper but blind to URLs.

Recall anchors
L4L7

Why it matters

L4 load balancers route by 4-tuple (IP, port). They're fast, simple, and can carry any TCP/UDP. L7 LBs parse application protocols (usually HTTP) and route by host, path, header, cookie. They're richer but slower per packet and tied to the protocol.

Deep dive

L4: NLB, Maglev — line-rate, connection-aware. Best for raw TCP services and very high throughput.

L7: ALB, Envoy, nginx — content-aware. Best for HTTP/HTTPS apps that need path/host routing.

Layered: L4 in front of L7 is common for global front-doors.

Demo / scenario

Build a global API edge.

  1. L4 anycast IP terminates TCP near user.
  2. Forward to regional L7 cluster.
  3. L7 routes /v1 → service A, /v2 → service B.
  4. Per-host limits applied at L7.

Tradeoffs

  • L4 is cheaper but blind to URLs.
  • L7 enables clever routing but adds CPU per request.
  • Mixing levels is normal at scale.

Diagram

User
L4 LB
L7 LB
Services
Layered L4 → L7 design.

Mind map

Check yourself

Loading quiz…

Sources & further reading