Notesfoundations🌱 seedling

L4 vs L7 Load Balancing

Also: Layer 4 Load Balancing · Layer 7 Load Balancing · Network Load Balancer · Application Load Balancer

An L4 balancer routes connections using addresses and ports, without reading the payload. An L7 balancer is a proxy that reads each HTTP/gRPC request and routes each one separately. L4 is fast and generic; L7 is smart and costly.

Why it exists

The layer a balancer understands decides its unit of balancing, its cost per byte and what it can route on.

How it works

  • L4: on a new flow, hash the 5-tuple (protocol, source and destination addresses and ports) to pick a backend, then forward every packet of that connection there. TLS passes through. It can run in the kernel (XDP) or on the NIC, and it can preserve the client IP.
  • L7: terminate the client connection (and TLS), parse each request, open a separate upstream connection, and choose a backend per request. It can route by path or header, retry, rewrite, rate-limit and emit per-request metrics.
  • Layering: large systems put an L4 tier in front of a fleet of L7 proxies.

Trade-offs

L4 L7
unit connection / flow request
cost very low parsing, buffering, two connections
features spread flows routing, retries, observability
weak spot long-lived multiplexed connections CPU, latency, more to misconfigure

In practice

  • AWS: NLB is L4 (flow hash, each TCP connection pinned to one target); ALB is L7.
  • Kubernetes Services (kube-proxy) balance per connection, which is why gRPC over HTTP/2 often loads one pod and idles the rest unless you add an L7 proxy or client-side balancing.

Pitfalls

  • L4-balancing HTTP/2 or gRPC: one long-lived connection carries thousands of requests to one backend.
  • Assuming L7 is free: TLS termination and per-request parsing cost CPU, and an L7 bug can break every route at once.

Recall

These cards are also in your review deck, scheduled with spaced repetition.