For each request, the load balancer picks two servers at random and sends the request to the one with fewer requests in progress. It looks at two servers instead of all of them, yet spreads load nearly as well as least connections, and it copes far better when its information about the servers is a little out of date. Below, compare it with least connections and random on the same traffic.
Each server drawn stands for one of your servers, and each dot for 100 real requests. "In progress" under the balancer is the live count; with load reports on, the line below it is what the balancer actually decides from. Switching the algorithm restarts the run with exactly the same requests.
Busiest hour vs the daily average. The book's estimate uses 2x.
Measured by load testing one server until it cannot go faster.
Headroom for spikes and unevenness. 50 to 70% is common.
1. Average requests per second
2. Peak requests per second
3. Servers needed n
4. Load on each server, on average
5. Servers looked at per request
6. Herding, with load reported every T seconds
Steps 1 and 2 are the estimation method from the back-of-the-envelope chapter of Alex Xu's System Design Interview, Vol. 1, including its 2x peak. Step 6 is a worst case: in practice requests that complete between reports soften it, but every new request in the window is still aimed at the same server. The claim that two choices is nearly as good as checking every server is the research result Envoy's documentation cites (Mitzenmacher and others).
Envoy makes it its least request method; NGINX offers it as a variant of random.
random two tells NGINX "to randomly select two servers and then choose a server using the specified method." "The default method is least_conn", so by default it is exactly the algorithm on this page.Both are the projects' own documentation (primary sources). Quoted phrases are short attributed quotations; everything else is described in our words. Check the pages for current behaviour.