Skip to content
nonconvexcard

Load Balancing and the Power of Two Choices

Why sampling two servers and taking the shorter queue is exponentially better than sampling one, and why least-outstanding-requests beats round robin for variable work.

AI SystemsAdvanced⏱ 1 hour7 min readload balancingballs into binspower of two choicesround robinleast loaded
1 problem →

One choice

TheoremMaximum load under uniform random assignment

Throw nn balls independently and uniformly into nn bins. Then with probability tending to 11, the maximum load is

(1+o(1)) ln⁡nln⁡ln⁡n.\bigl(1+o(1)\bigr)\,\frac{\ln n}{\ln \ln n} .

Assumptions

The matching lower bound is a second-moment argument that we do not reproduce; it is the harder half and is given in the cited literature. The upper bound is proved below, which is the direction a system designer needs — it says the imbalance is no worse than this.

PropositionA log n / log log n upper bound for one choice

With nn balls in nn bins, for k≥1k \ge 1,

Pr⁡[some bin has≥k balls]  ≤  nk!.\Pr[\text{some bin has} \ge k \text{ balls}] \;\le\; \frac{n}{k!} .

Consequently, taking k=⌈eln⁡n/ln⁡ln⁡n⌉k = \lceil e\ln n/\ln\ln n\rceil makes this o(1)o(1), so the maximum load is O(ln⁡n/ln⁡ln⁡n)O(\ln n/\ln\ln n) with high probability.

Two choices

TheoremThe power of two choices

Throw nn balls into nn bins, each ball choosing d≥2d \ge 2 bins uniformly at random and going into the least loaded of them (ties broken arbitrarily). Then with probability tending to 11 the maximum load is

ln⁡ln⁡nln⁡d  +  Θ(1).\frac{\ln\ln n}{\ln d} \;+\; \Theta(1) .

Assumptions

Stated without proof; the argument is a layered-induction bound on the number of bins with load at least kk, given in full in the cited paper. What matters here is the shape: ln⁡ln⁡n\ln\ln n rather than ln⁡n/ln⁡ln⁡n\ln n/\ln\ln n, and a further improvement only in the constant 1/ln⁡d1/\ln d as dd grows beyond two.

Simulating nn balls into nn bins, averaged over five runs:

nnd=1d=1 max loadln⁡n/ln⁡ln⁡n\ln n/\ln\ln nd=2d=2 max loadln⁡ln⁡n/ln⁡2\ln\ln n/\ln 2
10310^35.83.573.02.79
10410^46.64.153.03.20
10510^57.84.713.23.53

Key idea

The gain from d=1d=1 to d=2d=2 is exponential; the gain from d=2d=2 to d=3d=3 is a factor ln⁡3/ln⁡2≈1.58\ln 3/\ln 2 \approx 1.58 in the leading term, and from d=3d=3 onward it is diminishing. Two probes is the whole trick. This is why production balancers sample a small constant number of backends rather than maintaining a global ordering — the global information is worth almost nothing beyond what two random samples already provide, and it costs a coherency term of the kind Scaling Limits — Amdahl, Gustafson and the Coherency Penalty warns about.

What to measure when you probe

PropositionRound robin ignores the information that matters

Let servers be identical and let request ii have service time SiS_i. Round robin equalises the count of requests routed to each server. Least-outstanding-requests equalises the number currently in service. These coincide only if the SiS_i are equal; in general, by Little's law applied per server, the occupancy of server jj satisfies

Lj  =  Xj E[Wj],L_j \;=\; X_j\,\E[W_j],

so equalising LjL_j equalises the product of throughput and latency — the actual load — whereas equalising the routed count equalises XjX_j alone.

Key idea

For LLM serving the service-time coefficient of variation is large — generations differ in length by orders of magnitude — so round robin and occupancy-based balancing are not close. By the Pollaczek–Khinchine formula in Queueing and the Utilisation Wall, queueing delay scales with 1+cs21+c_s^2; routing on counts lets that variance land unevenly, while routing on occupancy absorbs it.

What this does not say

The theorems here are about static balls into bins, where balls never leave. The queueing version — the supermarket model, where jobs arrive and depart — is analysed in the second reference and has the same qualitative conclusion, with the maximum queue length under d=2d = 2 decaying doubly exponentially in the load rather than singly. The static statement is quoted because it is the one with a clean, checkable form; the dynamic statement is the one that actually applies to a serving system.

References

These works are cited as sources to read, not reproduced. All exposition, examples and problems on this site are written independently; where an argument is standard, the citation points to a canonical treatment.

Results stated on this page

Problems (1)

All problems