CONCEPT SHEET · Concepts

Load Balancers

One-liner: Distribute traffic across healthy backends to scale horizontally and hide failures; L4 balances connections, L7 balances requests.

ArticleConcepts© Arthur Bernier Jr592 words1 code block

Say this#

How it works#

TEXT
DNS/anycast (GSLB) -> region   -> [L4 LB pair, VIP via VRRP]  -> [L7 LB / gateway x N] -> service instances
  1. Client resolves DNS to a regional VIP (or anycast IP).
  2. L4 LB spreads TCP connections to L7 LBs (or straight to services).
  3. L7 LB terminates TLS, inspects request, applies routing (host/path), picks a backend via algorithm.
  4. Health checks remove failing instances; connection draining on deploys.
  5. LB itself is redundant: active-passive pair with a floating VIP, or active-active behind ECMP/anycast. Cloud LBs (ALB/NLB) are managed, multi-AZ by default.

Trade-offs#

ChoiceProCon
L4Millions of conns, protocol-agnostic, low latencyNo content routing, no per-request balancing (long-lived conns skew)
L7Smart routing, TLS offload, retries, observabilityMore CPU, more latency, more config surface
Round robinSimpleIgnores backend load and request cost
Least connectionsAdapts to loadNeeds connection tracking; herd to a fresh node
Consistent hashingCache affinityHot keys; uneven load
Sticky sessionsLegacy apps workBreaks on scale-in; hot nodes; use Redis sessions instead
Hardware/managed LBTurnkey HACost, less control

Numbers#

  • Nginx/HAProxy on a modern box: tens of thousands of HTTP req/s per core order of magnitude; L4 (IPVS/NLB) handles millions of concurrent connections.
  • Typical health check: every 5-30 s, 2-3 consecutive failures to eject, 2 successes to re-add.
  • LB hop latency: sub-millisecond for L4, ~1 ms for L7.
  • Connection draining defaults: AWS ALB 300 s deregistration delay.

In the interview#

See also