Load Balancing
What a load balancer does
- Distributes client traffic across multiple backends to improve availability and scale.
- Often provides health checks, TLS termination, routing, and observability.
Layer 4 vs Layer 7 load balancing
- L4: based on TCP/UDP (IP:port); fast, less context (no HTTP awareness).
- L7: understands application protocol (HTTP headers/paths); supports routing rules and richer policies.
Round robin, least connections, etc.
- Round robin: rotate through backends.
- Least connections: send to the backend with fewest active connections.
- Weighted variants: allocate proportionally for canaries or heterogeneous capacity.
Health checks
- Periodic probes determine if a backend should receive traffic.
- Must reflect real readiness (dependency health, warm caches) to avoid “flapping”.
Sticky sessions
- Routes the same client to the same backend (cookie/IP hash).
- Useful for in-memory session state; tradeoff: uneven load and harder failover.