Networking & Protocols (50 Qs)•Part 3: Advanced Internals, Scale & Production Patterns (Senior / Lead)
What is the difference between Layer 4 Load Balancing and Layer 7 Load Balancing?
senior Levelnetworking-protocolsAdvanced Internals
In Simple Words:
- Layer 4 (Transport / TCP/UDP): Operates strictly on IP and Port (e.g. AWS Network Load Balancer, IPVS, HAProxy in TCP mode):
- Does not inspect HTTP headers or payload.
- Blazing fast, consumes minimal CPU, handles millions of connections, but cannot route based on URL path or cookies.
- Layer 7 (Application / HTTP): Terminates TCP and TLS, parses full HTTP headers and URLs (e.g. Nginx, Envoy, AWS ALB):
- Routes based on path (
/apivs/static), inspects cookies, rewrites headers, injects WAF rules. Higher CPU overhead.
- Routes based on path (