System design fundamentals learning path Level 1 This level · 2 of 6
Easy system-design fundamentals

What does a load balancer do, and what is the difference between L4 and L7 load balancing?

The 30 second answer

A load balancer spreads requests across healthy servers so no single one is overloaded and a failed one stops getting traffic. A layer 4 balancer routes TCP or UDP connections by address and port without reading the request, so it is fast and protocol-agnostic. A layer 7 balancer understands HTTP, so it can route by path, host or header, terminate TLS and retry, at the cost of more work per request.

Could you say this in an interview?

L4 versus L7, with the AWS definitions. AWS documents that a Network Load Balancer functions at the fourth layer of the OSI model and can handle millions of requests per second; it picks a target per connection. An Application Load Balancer functions at the seventh layer: it evaluates listener rules in priority order, for example on path or host, and then selects a target from the matching target group.

  • Use L4 for raw TCP or UDP, very high connection counts, non-HTTP protocols, or when you want TLS to pass through to the backend.
  • Use L7 for HTTP APIs and websites when you need path-based routing (/api to one service, /static to another), header-based routing, redirects, or per-request metrics.

Balancing algorithms. NGINX documents the common ones:

  • Round-robin (the default): each server gets requests in turn.
  • Least connections (least_conn): send to the server with the fewest active connections, which is better when request durations vary.
  • IP hash (ip-hash): the client IP decides the server, giving session persistence.
  • Weighted: give bigger servers a bigger share.

Health checks. The balancer must stop sending traffic to a broken instance. On AWS, an ALB target group probes each target every HealthCheckIntervalSeconds, and marks it unhealthy after UnhealthyThresholdCount consecutive failures; healthy again after HealthyThresholdCount successes. NGINX open source also has passive checks: a server that fails max_fails times within fail_timeout is taken out for a while.

Common mistakes interviewers listen for.

  • Making the load balancer itself a single point of failure. Managed balancers run nodes in several Availability Zones; with self-hosted ones you need redundancy.
  • Health checks that only test "process is up" (/ping) and miss a dead database connection, or deep checks that fail every instance at once when one shared dependency is slow.
  • Sticky sessions as the default. They make scaling and draining harder; keep servers stateless and put session state in a shared store.

Alternate interview scenarios

"Why can one server still get much more traffic than the others?"

Long-lived connections (HTTP/2, gRPC, WebSockets) are balanced once per connection by an L4 balancer, so a client that opened its connection early keeps hitting the same backend. For gRPC that is covered in more detail on API, REST, gRPC and MCP compared.

Sources (4)
  1. AWS: What is a Network Load Balancer?docs.aws.amazon.com
  2. AWS: What is an Application Load Balancer?docs.aws.amazon.com
  3. AWS: Health checks for Application Load Balancer target groupsdocs.aws.amazon.com
  4. NGINX: Using nginx as HTTP load balancernginx.org
Previous
Next