System Designsimulator

Load balancer race

A load balancer has one job: decide which backend gets the next request. The simple rules work well when every backend is the same. They fall apart the moment one is slower than the rest, and in real fleets one always is: a noisy neighbour, a cold cache, a garbage collection pause.

60 s of 60 s
One slow backend

Least connections keeps p99 latency to 1.91 s; Round robin reaches 1.5 min.

p99 gap48×Highest p99 ÷ lowest p99

Requests waiting or in service, per backend

Bar height uses one scale for every algorithm: the tallest bar is 240 requests.

Round robin
Random
Least connections
Power of two choices
Weighted round robin

Backends and traffic

The last backend serves this share of a healthy backend’s speed. 100% means every backend is healthy.

Arrival rate as a share of the total capacity of all backends.

The same seed gives the same request stream to every algorithm.

Every algorithm on the same requests

Latency for all 1,590 requests, including the backlog
Algorithmp50p99To slow node
Round robinTakes the backends in turn and ignores how busy they are.229.3 ms1.5 min25%
RandomPicks any backend at random.280.5 ms1.4 min23.6%
Least connectionsLowest p99Sends each request to the backend with the fewest requests in progress.150.4 ms1.91 s8.9%
Power of two choicesPicks two backends at random and uses the less busy one.192.2 ms3.04 s8.8%
Weighted round robinTakes turns in proportion to fixed weights, set here from each backend’s speed.222.3 ms2.98 s8.6%
Why the slow node hurts round robin

The slow backend can serve about 7.4% of the traffic. Round robin sent it 25%, so its queue is 240 requests deep and still growing; every request stuck behind it waits. Least connections sent it 8.9%: a backend that falls behind has more requests in progress, so it is picked less. Its queue is 3. Power of two choices gets most of the benefit by looking at only two backends per request, and sent it 8.8%. Weighted round robin also protects the slow node, but only because we gave it the speeds in advance.

What it shows

This simulation sends the same random stream of requests to five algorithms at once. Each backend is a queue that serves one request at a time. You can slow down one backend and watch what each algorithm does about it.

Round robin and random never look at how busy a backend is, so they keep feeding the slow one its full share. Least connections counts requests in progress. Power of two choices looks at only two backends, picked at random. Weighted round robin does not look at all, but is told each backend’s speed in advance.

How to read it

  • Press Play to run a minute of traffic, or step one second at a time. The page opens on the finished run.
  • In the table, p50 is the typical request and p99 the slowest in a hundred. Mid-run it covers requests finished so far; at the end it covers all, including the backlog.
  • The last column is the share of requests sent to the slow backend. Its fair share is its speed divided by the total speed, so a backend at 25% speed among three healthy ones should get about 7%.
  • Each bar chart shows requests waiting or in service on each backend. All five use one scale, and the slow backend is hatched and labelled “slow”.
  • Backends is the number of servers, from 2 to 12. Load is the arrival rate as a share of total capacity. Seed picks the random stream; change it to check a result is not a fluke.

Questions

Why does least connections handle a slow server well?

A slow server finishes requests more slowly, so it has more requests in progress. Least connections reads that as a busy server and sends new requests elsewhere, with no need to know how fast anything is. It needs a count of in-flight requests per backend, which the load balancer already has.

How can picking from just two random backends work so well?

Mitzenmacher showed that when each request chooses the less loaded of two random servers, the busiest server’s queue grows far more slowly than with one random choice: roughly ln ln n instead of ln n ÷ ln ln n for n servers. A second look is almost all of the benefit. It also needs no global view of the fleet, which is why it suits large and distributed load balancers.

When is round robin the right choice?

When backends are the same size and requests cost about the same. It keeps no state, adds almost no overhead and is easy to reason about. Set the slow backend to 100% and it sits within a factor of two of the cleverer algorithms here.

Does weighted round robin fix a slow server?

Only if the weights are right. Here they come from each backend’s speed, which the algorithm is told up front. A backend that slows down later, with weights unchanged, is overloaded just like round robin overloads it. Algorithms that watch queue length adapt without being told.

How realistic is this model?

Each backend is a single queue with random service times and requests arrive at random, the M/M/1 model. Real services have several workers, uneven request sizes and bursty traffic, which usually makes waiting worse. The shape of the result, a slow backend ruining the tail under oblivious routing, is what carries over.

Learn it properly

Sources

Explore further

Last updated

More tools

All tools

Your first senior-level
lesson is free.

Choose a course, open a free lesson, and explore an idea you’ve wanted to understand.