1.L4 vs L7 load balancing
An 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.
Key features
- L4 (transport layer): routes by IP address and port, does not inspect request content
- L7 (application layer): routes by HTTP path, headers, cookies, or the request body
- L4 is faster and simpler — no parsing of the actual protocol payload
- L7 enables content-based routing: /api/* to one service, /static/* to another
- L7 can also terminate TLS, inspect headers for auth, and do sticky sessions by cookie
What each layer can see and decide on
- 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
Command
L4: route by (source IP, dest IP, port) — no payload inspection
L7: route by (HTTP method, path, host, header, cookie)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.