L4 vs L7 load balancing
coreintermediateAn L4 (transport-layer) load balancer routes by IP and port alone, without looking inside the request — fast, but blind to content. An L7 (application-layer) load balancer reads the actual HTTP request — path, headers, cookies — and can route on that, at the cost of more work per request.
Think of it as
An L4 balancer is like a mail sorting machine that only reads the zip code on the envelope — fast, but it has no idea what is inside. An L7 balancer is like a person who opens the envelope, reads the letter, and routes it based on what it actually says — slower per item, but able to make far more precise decisions.
What we're doing: Show the same traffic routed differently by an L4 balancer versus an L7 balancer.
- 5
- L4 cannot distinguish the two requests — it never looks past the IP/port.
- 10
- L7 parses the actual HTTP request to make a routing decision the L4 balancer structurally cannot make.
Why this works: Content-based routing (API traffic to one pool, static assets to another, or A/B testing by cookie) requires an L7 balancer — an L4 balancer physically does not have access to that information.
Expecting an L4 load balancer to route by URL path
Wrong
Better
What you see: Path-based routing rules configured on an L4 balancer are silently ignored or rejected at config time, because L4 never parses the HTTP request to find a path in the first place.
Why: The two layers see fundamentally different data. Choosing the right layer for the job is a prerequisite, not an implementation detail.
- L4 (transport layer)
- Sees only IP + port
- Cannot tell /api/orders from /static/logo.png
- Forwards any packet on port 443 to any backend IP
- Very low cost per request
- L7 (application layer)
- Reads the full HTTP request
- Routes /api/* to the orders-service pool
- Routes /static/* to the CDN origin pool
- Higher cost — parses the request
What each layer can see and decide on
Together
Remember: L4 routes by IP/port only, fast and content-blind; L7 reads the actual HTTP request and can route by path, header or cookie, at higher cost per request.
See also: load balancing algorithms · client server topology

