Why it matters

Every production system needs load balancing. Getting it right is invisible; getting it wrong causes cascading failures. Understanding the choices lets you architect systems that scale predictably.

Advertisement

The architecture

L4 (transport) load balancing operates on TCP/UDP. Fast, protocol-agnostic, but can't inspect payload. Examples: AWS NLB, HAProxy in TCP mode.

L7 (application) load balancing operates on HTTP. Can route by path, header, cookie. Slower but far more flexible. Examples: AWS ALB, NGINX, Envoy.

LB spectrumL4 LBTCP/UDP fastL7 LBHTTP flexibleHealth checksverify backendL4 for speed and any protocol; L7 for HTTP routing intelligence
Load balancer types.
Advertisement

How it works end to end

Algorithms: round-robin (simple, uniform distribution), least connections (routes to least-loaded), weighted (different capacity per backend), consistent hashing (for cache stickiness), IP hash (session stickiness).

Health checks: active (LB polls each backend) or passive (LB observes request results). Frequency and threshold determine failover speed vs false positives.

Session affinity: some workloads need requests from a user to hit the same backend. Cookie-based or IP-based stickiness.