Course contents

03. Scaling and Load Balancing Lesson 4 of 8

Round Robin

Go beyond take-turns: weighted and smooth round robin, why static weights miss slow servers, and how variable request sizes break count-based fairness.

14 minBeginner8 steps
Loading the interactive simulation…
Loading the knowledge check…

Summary

  • Round robin is a pointer that advances once per request: even by count, blind to load.
  • Weighted round robin sends requests in proportion to configured weights; keep them matched to capacity.
  • Smooth weighted round robin interleaves turns instead of sending each server a block of requests.
  • A degraded server keeps its weight and passes liveness checks, so round robin keeps feeding it.
  • Equal counts are not equal work when request sizes vary; load-aware algorithms handle that better.
Deep diveHow it works, trade-offs, failure modes, misconceptions and the interview angle.

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.

The lesson as textEvery step of the simulation, written out.
  1. 1. A pointer that moves one step per request

    Round robin keeps a single number per balancer: the index of the next server. Each request goes to that server and the index moves on: App 1, App 2, App 3, App 1, …

    It needs no knowledge of the servers, costs almost nothing per request and is perfectly even by count: at 150 requests per second each server gets exactly every third request.

    Scene: The load balancer sends requests to App 1, App 2 and App 3 in turn. Each receives the same number of requests and is about two-thirds busy.

    Key idea: Round robin balances request counts, using no information about the servers.

  2. 2. One server is twice as big

    App 3 is replaced by an instance with twice the cores: it can do about 150 requests per second while App 1 and App 2 still do about 75. Traffic grows to 240 requests per second, which the three can handle together (300).

    Round robin still gives each server a third, 80 per second. That is more than App 1 and App 2 can take, so they saturate and start rejecting, while the big App 3 is only about half busy.

    Scene: App 3 has twice the capacity. Round robin still gives each server a third of 240 requests per second, so App 1 and App 2 are saturated and reject requests while App 3 is about half busy.

    Key idea: Equal counts on unequal servers: the small ones overload while the big one idles.

  3. 3. Weighted round robin

    We give each server a weight proportional to its capacity: App 1 = 1, App 2 = 1, App 3 = 2. Out of every four requests, App 3 now gets two.

    That is about 60 requests per second for each small server and 120 for the big one: every server is roughly 80% busy, the rejections stop and P95 drops. The balancer still knows nothing at run time; the knowledge is in the weights you configured.

    Scene: With weights 1, 1 and 2, App 3 receives twice as many requests as App 1 or App 2. All three are about 80% busy and nothing is rejected.

    Key idea: Weights encode capacity: each server receives requests in proportion to its weight.

  4. 4. Interleave, don’t burst

    A naive weighted round robin hands each server its whole weight in one block. With 1 : 1 : 2 that hardly matters, but with weights like 10 : 1 : 1 it means ten requests in a row to one server, a burst that can fill its queue.

    This balancer uses smooth weighted round robin (as nginx does): on every pick each server adds its weight to a running total, the highest total wins and pays back the sum of all weights. Here the cycle is 3, 1, 2, 3: exact proportions in every four requests. With 10 : 1 : 1 the two small servers’ turns land inside the big server’s run, so its longest burst is much shorter than ten.

    Scene: The balancer repeats the cycle App 3, App 1, App 2, App 3. In every four requests App 3 gets two and the others one each.

    Key idea: Smooth WRR keeps the proportions but spreads each server’s turns through the cycle.

  5. 5. Slow is not down

    One second in, App 3’s disk starts failing and every request takes four times as long. It is still answering health checks, so the balancer keeps it in rotation, and its weight still says "give me half".

    App 3 can now do fewer than 40 requests per second but keeps receiving about 120. Its queue fills and it rejects requests while the two small servers have room. Weights are static: they describe the servers you configured, not the servers you have right now.

    Scene: App 3 becomes four times slower but stays in rotation with weight 2. It is overloaded and rejects requests, while App 1 and App 2 are not fully busy.

    Key idea: Static weights cannot react to a server that becomes slow; health checks only catch servers that stop answering.

  6. 6. Requests are not all the same size

    App 3 is repaired. Now a different problem: real requests vary. Most are quick, but a few (a big report, a large upload) take many times the average. We keep the same average work but make it highly variable.

    Round robin still deals out its counts, yet one server can end up with several heavy requests at once while another sits on quick ones. Quick requests queue behind heavy ones: P95 and P99 rise sharply and some requests are rejected, although the average work per request is unchanged.

    Scene: All servers are healthy again, but request sizes now vary widely. Round robin still splits requests 1 : 1 : 2, and tail latency is much higher than before, with occasional rejections while another server has spare workers.

    Key idea: Even counts are not even work: variable request sizes make round robin queue behind heavy requests.

  7. 7. When to look at load instead

    Round robin cannot see work in progress. Least connections can: it sends each request to the server with the fewest requests in flight, so a server stuck with heavy requests gets skipped. Switch to it: rejections fall sharply and P95 drops. P99 stays high, because those are the heavy requests themselves; no balancer makes a big request small. (Plain least connections ignores that App 3 is bigger; real balancers offer a weighted variant.)

    At large scale, with many balancers, the popular compromise is power of two choices: pick two servers at random and take the less busy one. The next lesson goes deeper.

    Scene: The balancer now uses least connections. With the same variable request sizes, far fewer requests are rejected and P95 is lower; the slowest one percent, the heavy requests themselves, are still slow.

    Key idea: Use round robin for uniform work; use a load-aware algorithm when work per request varies.

  8. 8. Where round robin fits

    Round robin is the right default when servers are identical and requests are short and similar: stateless APIs on one instance type, DNS records, TCP connection spreading. Add weights when capacities differ, and keep them in sync with reality.

    It misleads when servers slow down without failing and when request sizes vary widely. Then pick an algorithm that looks at load, and still watch per-server latency so a sick server is noticed.

    Scene: Three healthy servers with variable request sizes behind a least-connections balancer.

    Key idea: Round robin is cheap, predictable and blind; know when blind is good enough.