What it is
Weighted round robin (WRR) is round robin where each backend has a weight. Over a cycle, each backend receives requests in proportion to its weight: with weights 1 : 4 : 2, one, four and two of every seven requests. The weights are configuration; the balancer itself still looks at nothing at run time.
This lesson assumes the Round Robin lesson, which introduces weights and the smooth variant. Here the focus is on where weights come from, how they go wrong, and how they interact with failures and restarts.
Why it exists
Fleets are rarely uniform. Instance generations change, a migration leaves old and new machines side by side, one pool runs on larger hosts, spot capacity comes in odd sizes. Plain round robin gives every backend the same count, so the smallest one saturates first: the usable capacity of the fleet becomes number of servers × smallest server. Weights let each server take a share proportional to what it can do.
How it works
Capacity. For a request/response service, a server’s throughput is roughly workers ÷ time per request (Little’s law): 16 workers at 50 ms is about 320 req/s; 4 workers at 25 ms is about 160 req/s. Weights proportional to these numbers make every server run at the same utilisation.
Smooth selection. Naive WRR serves each backend its weight in a block (four in a row to the big one). Smooth WRR (nginx’s algorithm, also used in the simulation) keeps a running score per backend: each pick adds every backend’s weight to its score, picks the highest, and subtracts the total weight from the winner. With 1 : 4 : 2 the cycle is L, F, L, S, L, F, L: exact proportions per cycle and no back-to-back picks of the heavy server.
Failures. When a backend is ejected by health checks, the others keep their relative weights. Its share is spread over the survivors in their ratio, so the biggest survivors absorb the most.
Slow start. Many balancers can ramp a newly healthy backend’s weight from a small value to its configured weight over a window (for example HAProxy’s slowstart, nginx Plus’s slow_start, Envoy’s slow-start mode, AWS ALB’s slow-start duration). Pre-warming the instance before registering it is the alternative.
When to use it
- Mixed instance types or generations behind one balancer, with stable and known capacities.
- Gradual traffic shifting: canary releases (weight 1 of 100 for the new version) and blue/green cut-overs use the same mechanism.
- Weighted DNS records or weighted target groups when splitting traffic across regions or clusters.
- Requests are short and similar in cost, so counts are a good proxy for work.
When not to
- Capacities change at run time (autoscaled mixed instances, noisy neighbours, degraded hosts): a load-aware algorithm adapts on its own.
- Request costs vary widely: equal counts in proportion to weight still pile heavy requests onto one server; use least outstanding requests (weighted, if capacities differ).
- Stateful affinity is needed (caches, sessions): use hashing, possibly with weights on the ring.
Trade-offs
| Choice | You gain | You pay |
|---|---|---|
| Weights from measured throughput | Equal utilisation, full fleet capacity | Load tests or per-backend metrics; must be redone after changes |
| Weights from specs (vCPU, memory) | Easy to set | Wrong whenever per-core speed, code or request mix differ |
| Slow start | No error spike from cold servers | Survivors carry more for longer; must have headroom |
| Weighted least connections instead | Adapts to slow servers and heavy requests | Needs in-flight tracking; weaker with many balancers that each see only part of the load |
Alternatives
- Weighted least connections / least outstanding requests: divides in-flight requests by weight and picks the lowest; reacts to slowness.
- Power of two choices (weighted): sample two backends with probability proportional to weight, pick the less loaded one; scales to many balancers.
- Adaptive weights: some proxies adjust weights from observed latency or error rate (for example Envoy’s outlier detection, or client-side load reports in gRPC’s weighted round robin policy).
- Homogeneous pools: keep one instance type per pool and balance pools separately; simplest when you control the fleet.
Failure modes
- Stale weights: a code change makes one instance type relatively slower; its weight now over-feeds it and P95 rises with no failure anywhere.
- Largest server fails: its share lands on smaller machines that cannot carry it; a fleet sized for “any one server” must use the largest one in the N+1 calculation.
- Cold return at full weight: a restarted server passes liveness checks and is immediately given its full share while caches and JIT are cold, producing a second error spike.
- Degraded but alive: health checks pass, the weight stays, the slow server keeps receiving its share (see the Round Robin lesson).
- Weights across balancers: each balancer instance runs its own smooth cycle; proportions hold per balancer, not globally per instant.
In production
Derive weights from per-backend throughput at your latency target, measured by load test or from production metrics, and store them with the instance type, not by hand per host. Alert on per-backend utilisation and latency skew: with correct weights, utilisation should be roughly equal across backends. Use slow start or pre-warming for services with caches or JIT warm-up. When capacity plans assume a mixed fleet, compute headroom with the largest backend removed. For canaries, use weights to send a small, fixed fraction to the new version and widen it gradually.
Common misconceptions
- “Weight = number of cores.” Cores differ in speed across generations, and the bottleneck may be memory, I/O or a downstream call. Measure.
- “Weighted round robin balances latency.” It balances utilisation if the weights are right. A server with a faster CPU still answers faster; a server with more but slower workers answers slower at the same utilisation.
- “Healthy means ready for full load.” A health check says the process answers, not that it is warm.
- “Weights fix slow servers.” Only if someone updates them. Static weights cannot see run-time changes.
Interview angle
When an interviewer mentions mixed hardware, a migration or a canary, bring up weights and say where the numbers come from (measured throughput, not specs). Then cover the failure cases: what happens when the largest node fails (N+1 around the biggest), how restarted nodes are ramped (slow start), and when you would switch to a load-aware algorithm. Doing the arithmetic out loud (“80 + 320 + 160 = 560 req/s; without the 320 node we have 240, so peak must stay below that or we add capacity”) shows real capacity thinking.
Model assumptions
The simulation is a simplified model, not a benchmark. Small has 4 workers at 50 ms mean service time (about 80 req/s), Large 16 workers at 50 ms (about 320 req/s), Fast 4 workers at 25 ms (about 160 req/s); service times are lognormal with cv 0.4 and each server queues up to 16 requests before rejecting. Arrivals are Poisson. The balancer uses smooth weighted round robin; health checks probe every 250 ms, with 2 failures to eject and 2 successes to restore. “Cold” is modelled as half speed for the first seconds after a restart, and slow start as a manual weight change from 2 to 4; real balancers ramp continuously over a configured window. Utilisation is the fraction of busy workers, not CPU. All numbers are illustrative.