Power of two choices

Also known as: power of two random choices

On this page 6

The power of two choices is a randomized load balancing algorithm that picks two servers at random for each request and sends the request to whichever of the two is less loaded. Also called the power of two random choices, it sits between purely random assignment and full least connections in networking, offering near-optimal balance with very little coordination.

The idea comes from probability theory on balls-and-bins processes, where adding a single extra random choice reduces the worst-case imbalance exponentially. Modern proxies, service meshes and schedulers adopt it because it scales to large fleets and tolerates stale load information far better than strict least-loaded selection.

How the power of two choices selects a server

For each incoming request, the balancer draws two distinct backends uniformly at random from the healthy server pool. It compares a load metric for both, such as active connections, outstanding requests or a latency estimate, and forwards the request to the lower value. Ties are broken randomly.

The algorithm needs only two lookups per decision, regardless of fleet size, so its cost is constant. A full least connections scan, by contrast, must examine every server or maintain a sorted structure that all workers update.

The mathematical result explains its strength. When n requests are placed into n servers purely at random, the busiest server receives roughly log n / log log n requests. With two choices, the maximum drops to about log log n / log 2, a dramatic improvement that grows only extremely slowly with fleet size. Additional choices beyond two yield only a constant-factor gain.

The table below compares the expected maximum load in this classic model.

Choices per requestAsymptotic maximum loadPractical effect
One (random)log n / log log nNoticeable hot spots
Twolog log n / log 2 + O(1)Near-even distribution
d greater than twolog log n / log d + O(1)Small further improvement
All serversOptimal but stale-sensitiveHerding on shared data
Maximum load in the balls-and-bins model

Why two random choices beat least loaded selection

In real systems, load information is always somewhat stale. Each balancer instance sees only its own connections, and shared metrics arrive with delay. Strict least loaded selection then suffers from herd behavior: every balancer sends new traffic to the same apparently idle server until it is overloaded.

Random sampling breaks this synchronization. Because each decision compares a different random pair, no single server attracts all new requests, even when every balancer holds the same outdated view. This property makes the power of two choices especially suitable for distributed load balancing, where many independent proxies or clients make decisions in parallel.

The following table places the method among neighboring algorithms.

AlgorithmInformation neededBehavior with stale dataTypical use
Round robinNoneUnaffected but load-blindUniform, short requests
RandomNoneUnaffected but unevenSimple stateless setups
Least connectionsLoad of all serversProne to herdingSingle balancer, long sessions
Power of two choicesLoad of two serversRobustDistributed proxies, meshes
Consistent hashingKey and ring layoutUnaffected, cache-awareSticky or cache workloads
Comparison with related load balancing algorithms

Implementations and configuration

Several widely used proxies implement the method directly. Envoy Proxy uses it as the default behavior of its least request policy when backends have equal weights, comparing active request counts. NGINX offers the random two least_conn directive, and HAProxy provides a random(2) balance option, where the number of draws is configurable.

Client-side load balancing libraries such as Finagle and several gRPC resolvers apply the same principle with a latency-weighted metric, often an exponentially weighted moving average of response time. This variant is sometimes called peak EWMA and reacts quickly to slow servers.

Choosing the load metric matters more than the sampling itself, as the table below shows.

MetricStrengthWeakness
Active connectionsCheap, always availableIgnores request cost
Outstanding requestsFits HTTP/2 and gRPCNeeds per-request tracking
Latency EWMADetects slow or degraded hostsNoisy with low traffic
Weighted loadHandles mixed server sizesRequires accurate weights
Load metrics used with two random choices
  • Sample from healthy servers only, after health checks and outlier ejection.
  • Prefer distinct samples, since drawing the same server twice wastes the second choice.
  • Combine with connection draining so removed servers stop receiving new picks gracefully.
  • Use weights when servers differ in capacity, normalizing load by weight before comparison.

Limitations and common misconceptions

The power of two choices does not guarantee perfect balance. In small pools of three or four servers, the gain over least connections is minor, and the randomness can briefly favor one server. The benefit grows with fleet size and with the number of independent balancers.

It also does not preserve affinity. Requests from the same client land on different servers, so stateful applications still need sticky sessions or consistent hashing. Finally, the method only balances what its metric measures: if connections are cheap but some requests are expensive, a connection count can mislead the comparison.

Operators should also watch for slow-start effects. A freshly added server reports zero load and wins most comparisons in which it appears, so some implementations apply a warm-up period that ramps its effective weight gradually. Without it, a cold cache or an unwarmed runtime can turn the newcomer into a temporary bottleneck.

MisconceptionCorrection
More choices are always betterGains beyond two are small; herding returns as d grows
It replaces health checksIt assumes the sampled servers are healthy
It needs global stateEach balancer uses only local observations
It suits cache-affine trafficHashing keeps keys on the same node
Misconceptions and corrections

Explained without jargon

Picture a large supermarket with twenty checkout lanes. Walking past every lane to find the shortest one takes time, and if everyone does it at once, they all rush to the same lane. Choosing a lane completely at random is fast, but sometimes you end up in a very long line.

The power of two choices is a middle path: glance at two random lanes and join the shorter one. This tiny extra effort keeps almost every line short, and because each shopper looks at a different pair, crowds do not form in one place.

A typical use case

A video streaming company runs 48 sidecar proxies in front of 120 API servers inside a service mesh. Initially, each proxy used least request selection based on its own counters. During traffic spikes, many proxies saw the same newly restarted server as idle, sent it a burst of requests at once and pushed its 99th percentile latency above 900 ms.

The platform team switched the proxies to the power of two choices with an outstanding request metric. Each proxy now compares just two random healthy servers per request. Under the same peak load, request distribution became nearly even, and tail latency fell to about 180 ms without any shared state between proxies.