Four backends at 85% total load. B0 runs at a third of the speed of the others. Under round robin, which hands each backend the next request in turn, what happens to B0's queue over four seconds?
Round robin sends B0 a quarter of the requests, about 0.7 work-ms per ms here, and B0 can do 0.33. The excess never drains. Equal requests is not equal load when the servers differ.
A load balancer picks a backend for each new connection (L4) or each request (L7). Round robin gives every backend the same number of requests. That is only fair when backends are equally fast and requests are equally big. Neither is true in production.
Load-aware policies look at outstanding requests instead. Least outstanding scans every backend. Power of two choices samples two at random and takes the less busy one. It keeps queues nearly as even while reading two counters, not N. Health checks cover what counters cannot see: a dead backend that refuses connections has zero outstanding requests.
▶ SIMULATION
0 / 18
TRAFFIC
t = 0 ms
sent 0 · one every 20 ms
85% of fleet capacity · 20% of requests are 10× longer
LOAD BALANCER
policy: round robin
health checks: off
failed requests 0
BALANCE
fleet mean queue 0.00
busiest: B0 at 0.00 = 0.0× mean
warming up until 1000 ms
B0 (3× slower)queue 0 · mean 0.0 · peak 0 · sent 0
B1queue 0 · mean 0.0 · peak 0 · sent 0
B2queue 0 · mean 0.0 · peak 0 · sent 0
B3queue 0 · mean 0.0 · peak 0 · sent 0
✓ busiest backend's mean queue ≤ 2 × fleet mean (from t = 1 s)✓ a dead backend leaves rotation within 300 ms
SCHEDULE
01[LB]LB: round robin
02[TRAFFIC]traffic until t = 250 ms
03[TRAFFIC]traffic until t = 500 ms
04[TRAFFIC]traffic until t = 750 ms
05[TRAFFIC]traffic until t = 1000 ms
06[TRAFFIC]traffic until t = 1250 ms
07[TRAFFIC]traffic until t = 1500 ms
08[TRAFFIC]traffic until t = 1750 ms
09[TRAFFIC]traffic until t = 2000 ms
10[TRAFFIC]traffic until t = 2250 ms
11[TRAFFIC]traffic until t = 2500 ms
12[TRAFFIC]traffic until t = 2750 ms
13[TRAFFIC]traffic until t = 3000 ms
14[TRAFFIC]traffic until t = 3250 ms
15[TRAFFIC]traffic until t = 3500 ms
16[TRAFFIC]traffic until t = 3750 ms
17[TRAFFIC]traffic until t = 4000 ms
18[LB]report
Start of round robin scenario. 18 steps.
// round robin: fair to servers, blind to work
let next = 0;
function pick(backends) {
return backends[next++ % backends.length];
}
// power of two choices: sample two, take the less loaded
function pick(backends, rng) {
const live = backends.filter((b) => b.healthy);
const a = live[Math.floor(rng() * live.length)];
let b = live[Math.floor(rng() * (live.length - 1))];
if (b === a) b = live[live.length - 1];
return a.outstanding <= b.outstanding ? a : b;
}
The invariant strip compares each backend’s time-averaged queue with the fleet mean. Round robin and random fail on B0. Two choices and least outstanding hold it. In the last two scenarios a backend dies at 1 s: without health checks it stays in rotation and swallows requests.
TUNE ITNOT YET
The balancer picks d backends at random and sends the request to the one with fewer outstanding requests. At d = 1 that is plain random. Find the smallest d that keeps the busiest backend within 2× the fleet mean. Try a few BACKENDS values too.
GOAL: queues stay even with as few random picks as possible
FIX ITNOT YET
Implement power of two choices. backends is a list of { healthy, outstanding }; rng() returns a number in [0, 1). Return the index of the backend to use. Never pick an unhealthy backend. Read outstanding on at most two backends per call: at a thousand backends you cannot afford to scan them all. The grader runs a fleet with one slow backend.
IN PRODUCTION
Envoy's LEAST_REQUEST (power of two choices by default), NGINX least_conn and random two, HAProxy leastconn, AWS ALB least outstanding requests, and Kubernetes Services, which balance per connection at L4. Typical symptoms: one hot pod after a deploy, gRPC traffic stuck on one backend, and a crash that pulls traffic toward the dead node.
IN INTERVIEWS
“Design the load balancing for this service.” Separate L4 (per connection) from L7 (per request). Explain why round robin breaks with uneven backends or request sizes, then propose least outstanding or power of two choices. Add active health checks plus passive outlier detection, and mention slow start for new instances.
RECALL CARDSTap to flip. They join your review deck when you mark the lesson complete.