Interview Q&A / System Design

IntermediateQuick answer1 min readUpdated 3 Oct 2026

Can you give a simple example of when Layer 7 load balancing is necessary?

SHORT ANSWER

Layer 7 is needed when routing depends on request content, such as the URL path, headers or cookies. For example, sending /api traffic to API servers and /images traffic to a media cluster.

Explain it simply

Layer 4 balancers see only IP addresses and ports. They forward packets quickly but cannot read the HTTP request. Layer 7 balancers read the HTTP message, so they can make decisions on what the client actually asked for.

Use Layer 7 when you need:

  • Path-based routing: /api to one pool, /static to another.
  • Host-based routing: admin.example.com to an internal pool.
  • Header or cookie rules: send beta testers to a new version.
  • TLS termination and HTTP-level features like compression and caching.
  • Retry on a 503 from one server by trying another.

The price is more CPU and slightly more latency, because the balancer must terminate the connection and parse requests. If you only need to spread raw TCP traffic quickly, for a database proxy or a game server, Layer 4 is simpler and faster.

Example

Routing rules on an e-commerce site:

text
Path starts with /api     -> api-pool      (4 servers)
Path starts with /images  -> media-pool    (2 servers)
Cookie beta=1             -> canary-pool   (1 server)
Everything else           -> web-pool

None of these decisions are possible from IP and port alone.

What to say in the interview

"Layer 7 is needed whenever the routing decision depends on HTTP content: paths, hosts, headers or cookies. Layer 4 is faster and fine for plain TCP spreading. I would use Layer 7 for web traffic and Layer 4 in front of databases or non-HTTP services."

#load-balancing#networking

Related questions

Practise more System Design questions

Test your recall with short answers, then return to the detailed explanations when you need context.

Open System Design quick answers →

Get new questions like this by email

One short email when something new and useful lands. No spam, unsubscribe in one tap.

By subscribing you agree to the Privacy Policy.