MidNetworking

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

All 336 cloud engineer questions

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