Cianplan

Level 1: Foundations · L1.3 Load balancing, reverse proxies, API gateways

L4 vs L7 load balancing

Choose L4 or L7 based on routing needs, TLS and cost.

12 min · Free

What you take away

  • An L4 balancer moves TCP connections without looking inside them; an L7 balancer reads the HTTP request and can route on it.
  • Reading the request means terminating TLS, so an L7 balancer sees your plaintext and costs CPU per request.
  • L7 buys path and header routing, canaries, retries, rewrites and per-route policy — everything that needs to know what was asked.
  • Both layers hide the client's IP address unless you deliberately carry it: X-Forwarded-For at L7, the PROXY protocol at L4.

How the class is laid out

  1. The problem
  2. The simple version
  3. What each layer can do
  4. The client IP trap
  5. Check your understanding