Topic 9.4
Load Balancers
In one line
Round Robin, Least Connections, IP Hash, health checks — the front door of every scaled system.
Think of it like this
A bank with multiple teller counters and a person at the entrance directing each new customer to whichever counter is free or has the shortest line, instead of everyone crowding one teller.
Key ideas
- 01
L4 (transport): routes by IP/port, raw TCP — fast, no content awareness.
- 02
L7 (application): inspects HTTP (paths, headers, cookies) — routing, retries, auth-friendliness at the cost of parsing.
- 03
Round Robin: even rotation; simplest; ignores load and capacity differences.
- 04
Least Connections: send to the node with fewest active connections — better for uneven request lengths.
- 05
IP Hash: consistent node per client IP — session affinity 'for free' (with the stickiness caveats).
- 06
Health checks: LB stops sending to a failing node (HTTP /healthz, TCP probe) — THE load-balancer superpower.
- 07
DNS + LB topology: DNS → LB VIP → instance pool. Multiple LBs for HA.
Java / Spring map
- →
Spring Cloud Gateway / Ribbon-lite; actuator /health for LB probes.
Code & diagrams
Strategy table — read it as a decision tree.
Strategy | picks | when
Round Robin | next in rotation | equal-capacity, equal-cost requests
Least Connections | fewest active | mixed long/short workloads
IP Hash | hash(clientIp) | affinity without sticky cookies
Weighted RR | rotation × capacity | heterogeneous nodes
Plus, always:
- health checks (L7 GET /healthz, tolerated 2/3 to remove)
- idle connection draining before node shutdownExplain without notes
Why does IP Hash beat Round Robin for a legacy app that needs session affinity — and what's its weakness?
Practice
Specify the LB (L4 vs L7) for: TCP game server, HTTP API with rate limits by IP, gRPC internal service.
Trade-offs
- ↔
L7 gives routing power but adds latency + becomes a possible bottleneck itself — keep it thin.
Run it in production
You've designed it. Now build, operate, and break the same idea hands-on in the DevOps courses:
Completion checklist
I can pick an LB strategy by workload and always mention health checks.