Networking interview question · Most asked
Compare layer 4 and layer 7 load balancers. When would you use each?
Summary
Layer 4 balancers route TCP/UDP by IP and port, preserve the protocol, handle very high throughput and offer static IPs (AWS NLB, Azure Load Balancer). Layer 7 balancers understand HTTP, terminate TLS and route by host, path or headers, and integrate WAFs and authentication (AWS ALB, Azure Application Gateway, Google Cloud Application Load Balancer).
Longer Answer
Use L7 for web apps and APIs (path routing, HTTP/2 and gRPC, redirects, header manipulation). Use L4 for non-HTTP protocols, client IP preservation, fixed IPs for allow-lists, or extreme performance. Often both appear: an NLB in front for static IPs and an ALB or ingress behind it.
Key Points
- L4: IP/port, any TCP/UDP, static IPs.
- L7: HTTP-aware routing, TLS, WAF.
- Choose by protocol and features.
- They can be combined.
Deep dive: Networking Tutorial: Load Balancers
Explanation
What interviewers look for
Matching the choice to protocol and requirements.
More most-asked Networking questions
- How does NAT work, and what are its limits?
- What's the difference between TCP and UDP, and when would you choose UDP?
- What do 502, 503 and 504 errors from a load balancer usually mean?
- What is CIDR notation? How many usable addresses are in a /26, and in an AWS /26 subnet?
- How does DNS resolution work, and what does a record's TTL control?
- What does TLS provide, and how does certificate validation work?
- What happens, at the network level, when you type a URL into a browser and press Enter?
- What's the difference between stateful and stateless firewalls? Give cloud examples.