What it is
Round robin is the simplest load balancing algorithm: the balancer keeps an index into its list of healthy servers, sends each request to the server at that index and advances it by one, wrapping at the end. Weighted round robin extends it so that a server with weight 2 receives twice as many requests as one with weight 1.
Why it exists
A balancer must make a decision for every request or connection, often hundreds of thousands per second. Round robin makes that decision in constant time with one integer of state and no information about the servers. The result is predictable and easy to reason about: over any stretch of N requests, each of N servers receives one.
How it works
Plain round robin. The index moves on every pick. Servers that fail health checks are skipped. If several balancers run in parallel, each has its own index, so the global sequence is only roughly rotated, but the long-run counts stay even.
Weighted round robin. Each server gets an integer weight, usually proportional to its capacity (cores, instance size). The naive version repeats each server as many times as its weight in the rotation: weights 3 : 1 give A, A, A, B. That produces bursts: with 10 : 1 : 1, ten consecutive requests go to one server.
Smooth weighted round robin (the variant in nginx and many other balancers) avoids the burst. Every server has a running total. On each pick every total grows by that server's weight, the server with the largest total is chosen, and its total is reduced by the sum of all weights. Proportions are exact over each cycle, and a heavy server's turns are spread through the cycle instead of in one block. For weights 1 : 1 : 2 the cycle is C, A, B, C.
What it does not look at. Neither variant knows how busy a server is, how long its requests take or whether it has slowed down. All that knowledge sits in the weights, which are static until someone changes them.
When to use it
- Identical, stateless instances serving short, similar requests.
- Distributing new TCP connections at layer 4, where per-connection cost is similar.
- DNS-level distribution across several addresses.
- Servers of known, different sizes, with weights matched to their capacity (weighted round robin).
- Gradual traffic shifting, such as sending 5% to a canary by weight.
When not to
- When request costs vary widely (cheap lookups mixed with expensive reports): equal counts become unequal work.
- When servers can slow down without failing (noisy neighbours, failing disks, garbage-collection pauses).
- Long-lived connections (WebSockets, gRPC streams) whose activity differs: the connection count says little about load.
- When requests for the same key should reach the same server for cache locality; use hashing instead.
Trade-offs
| Choice | You gain | You pay |
|---|---|---|
| Round robin over load-aware algorithms | Constant-time picks, no state about servers, predictable | Blind to slow servers and variable request sizes |
| Weighted over plain | Uses differently sized servers properly | Weights to maintain; wrong weights overload servers silently |
| Smooth over naive weighting | No bursts to heavy servers | Slightly more computation per pick (negligible) |
| Per-balancer index | No coordination between balancers | Global rotation is only approximate |
Alternatives
- Least connections / least outstanding requests: sends work to the server with the fewest requests in progress, adapting to slow servers and heavy requests.
- Power of two choices: pick two servers at random, take the less loaded one; nearly as good as least connections and works well with many independent balancers.
- Random: as cheap as round robin and stateless even across balancers; similar long-run balance with more short-term variation.
- Consistent hashing: same key to the same server, for cache affinity.
- Latency-aware (EWMA) balancing: weights servers by recently observed response times.
Failure modes
- Stale weights: an instance is resized or a server degrades, but its weight stays the same, and it receives the wrong share.
- Slow but alive: a degraded server passes liveness checks and keeps its full share; its queue fills while others idle. Outlier detection on latency or error rate is the usual defence.
- Heavy-request pile-up: a few expensive requests land on the same server; everything behind them waits, and tail latency rises even though counts are even.
- Bursts with naive weights: high weights without smoothing send long runs of consecutive requests to one server.
- Synchronised balancers: many balancers that restart together and start at index 0 all hit the first server at once; randomising the starting index avoids it.
In production
nginx, HAProxy, Envoy and cloud balancers all offer round robin and weighted round robin, usually as the default. Set weights from measured capacity, not instance labels, and revisit them when hardware changes. Combine round robin with active health checks and passive outlier detection so that slow or erroring servers are removed. Watch per-backend latency and queue depth: a single hot backend behind an even request count is the signature of a round-robin mismatch. Many operators switch to least outstanding requests or power of two choices for request-level balancing at layer 7 and keep round robin for connection-level balancing at layer 4.
Common misconceptions
- "Round robin is fair." It is fair by count. Fairness by work requires equal servers and equal requests.
- "Weights make it adaptive." Weights are configuration, not measurement; they cannot follow a server that slows down.
- "Health checks catch slow servers." Liveness checks catch servers that stop answering. A server that answers slowly passes them.
- "Least connections fixes everything round robin gets wrong." It adapts to load, but a request that is expensive stays expensive; tail latency from heavy requests themselves remains.
Interview angle
Saying "round robin" is fine for a first answer; interviewers then look for the limits. Mention that it balances counts, not work; that weights handle known capacity differences but not degradation; and that for variable request costs you would choose least outstanding requests or power of two choices. Knowing smooth weighted round robin and the "slow is not down" failure mode signals production experience.
Model assumptions
The simulation is a simplified model, not a benchmark. Small servers have 6 workers, the large one 12, with an 80 ms mean service time (lognormal, cv 0.35; cv 2 for variable request sizes, same mean) and room for 12 waiting requests. Weighted round robin is the smooth variant. A degraded server takes four times as long per request and still passes health checks (every 500 ms). Least connections counts requests in flight per server and does not use weights. Arrivals are random (Poisson); network hops take a fixed 5–25 ms. Utilisation is the fraction of busy workers, not CPU. Numbers show behaviour and orders of magnitude only.