Networking for Interviews/Load Balancing, Proxies & CDN

L4 vs L7 Load Balancing

Packet-level vs request-level routing, health checks, sticky sessions, consistent hashing, and when ALB vs NLB (or nginx vs cloud LB) fits.

3/5Overview: 20m

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

NeedLean toward
Raw throughput, TLS passthrough, fixed IPL4 / NLB
Path-based routing, header routing, WAFL7 / ALB
Session stickiness without shared stateSticky 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.

Further Reading