Interview Prep/Networking/Load Balancing, Proxies & CDN

What is the difference between a Layer 4 and a Layer 7 load balancer?

BeginnerScenarioLoad Balancing, Proxies & CDN
Answer

Situation read → The layer decides what the balancer can see and therefore what it can route on.

What I'd do →

  1. L4 (NLB, HAProxy in mode tcp) balances on IP and port without reading the payload, so it is fast and protocol agnostic
  2. L7 (ALB, Nginx, Envoy) understands HTTP and can route on host, path, header or cookie
  3. L7 can terminate TLS, rewrite headers and do WAF or redirects
  4. Choose L4 for raw TCP/UDP, extreme throughput or static IPs, and L7 for web traffic

Why → The more of the packet the balancer parses, the smarter and the slower the decision gets.

Interview tip → Mention that NLB preserves the client source IP, while ALB does not and passes it in X-Forwarded-For.

All Networking questions Roadmap: Networking for DevOps

More on Load Balancing, Proxies & CDN