DevOps Engineer interview question · Most asked

Explain the difference between L4 and L7 load balancers and when to use each.

Summary

An L4 (transport-layer) load balancer forwards TCP/UDP connections based on IPs and ports without understanding the protocol: very fast, protocol-agnostic, preserves end-to-end TLS. An L7 (application-layer) load balancer understands HTTP: it can route by host, path and headers, terminate TLS, rewrite requests, apply WAF rules, and balance individual requests, including HTTP/2 and gRPC streams.

Longer Answer

Use L7 (for example AWS ALB, Envoy, NGINX) for web APIs and microservices needing routing and per-request balancing; use L4 (AWS NLB, HAProxy in TCP mode) for non-HTTP protocols, extreme throughput, static IPs, or when TLS must not be terminated. Related concepts: health checks, connection draining, sticky sessions (avoid when possible), and idle timeouts that must be aligned with application keep-alive settings.

Key Points

  • L4: connections, fast, protocol-agnostic.
  • L7: HTTP-aware routing, TLS, WAF.
  • Per-request balancing needs L7.
  • Align health checks and timeouts.

More most-asked DevOps Engineer questions

← All DevOps Engineer questions