What is the difference between a layer 4 and a layer 7 load balancer, and when would you use each?
What they are really testing: Whether you understand what each can see and do, and pick deliberately. The wrong layer means you cannot do path routing, or you pay overhead you did not need.
A real interview question
What is the difference between a layer 4 and a layer 7 load balancer, and when would you use each?
What most people say
drag me
“Layer 7 is newer and better, so you should use a layer 7 load balancer.”
It treats it as a version upgrade rather than a trade-off. L4 is the right choice for non-HTTP traffic and ultra-low-latency paths; "L7 is better" misses what each layer can actually see.
The follow-ups they ask next
You need to route /api and /app to different services on one domain. Which layer?
Layer 7: only it can see the URL path. An L4 balancer cannot read the request, so path-based routing is impossible there.
What do you lose visibility of when an L7 balancer terminates TLS and forwards HTTP?
The backend sees the balancer IP, not the client. You restore the client IP with X-Forwarded-For (or PROXY protocol on L4), and re-encrypt to the backend if the hop must stay private.
What the interviewer is listening for
- Frames it as "what can it see"
- Knows L7 enables path/host routing + TLS termination
- Knows L4 for non-HTTP/low-latency/client-IP
What sinks the answer
- "L7 is just better/newer"
- Thinks L4 can do path routing
- No sense of the overhead trade-off
If you genuinely do not know
Say this instead of freezing. Reasoning out loud from what you do know beats silence every single time, and a good interviewer is listening for exactly that.
“It is about what it can see. L4 routes by [IP and port without reading the payload, fast and protocol-agnostic]. L7 reads [HTTP, so it routes by host/path/header and can terminate TLS]. I use L7 for [web apps needing path routing or TLS termination] and L4 for [non-HTTP, ultra-low-latency, or preserving the client IP].”
Keep going with networking
Foundation
What is a VPC, and what is a subnet within it? Why split a network into subnets at all?
Foundation
What is the difference between TCP and UDP, and when would you choose each?
Foundation
What happens, step by step, when you type a URL into a browser and press enter?
Foundation
How does DNS resolution actually work, and what is the difference between an A record and a CNAME?
Foundation
What is the difference between IPv4 and IPv6, and why does IPv6 exist?
Junior
An EC2 instance in a private subnet needs to download OS updates from the internet. Walk me through how you make that work, and why.
Knowing the answer is not the same as recalling it under pressure
Sign in to send the questions you fumble to spaced recall, so they come back right before you would forget them, and learn the concepts behind them with hands-on labs.
Start free