L4 (transport) load balancing
Operates on IP + port. Fast, protocol-agnostic, can't route based on URL path or Host header. NLB-style — millions of RPS, static IPs, TLS passthrough common.
Algorithms: round-robin, least connections, consistent hashing (sticky by source IP or hash key — reduces cache miss when scaling).
L7 (application) load balancing
Terminates HTTP, reads Host, path, headers, cookies — route /api vs /static, A/B tests, auth at edge. ALB-style — integrates with WAF, certificates, health checks on HTTP endpoints.
Health checks
LBs remove unhealthy targets from rotation. Know graceful drain vs abrupt removal — in-flight requests need time to complete.
Consistent hashing (interview favorite)
When you add/remove nodes, only a fraction of keys remap — critical for distributed caches and sharded systems. Pair with virtual nodes to balance load evenly.
Trade-off summary
| Need | Lean toward |
|---|---|
| Raw throughput, TLS passthrough, fixed IP | L4 / NLB |
| Path-based routing, header routing, WAF | L7 / ALB |
| Session stickiness without shared state | Sticky sessions or consistent hash (know downsides) |
Sticky sessions break when instances die — prefer external session store or stateless JWT for new designs unless legacy requires it.