Scrivio Interview library
ConceptFoundations6 min read · updated 13 November 2026

A load balancer must choose a backend for each request or connection. Common algorithms include round robin, weighted round robin, least connections, least outstanding requests, random with two choices, and hashing on a key.

Explain how each works and give a situation where each is the right choice.

Round robin sends requests to backends in turn and suits identical backends with similar requests; weighted round robin gives bigger instances more. Least connections or least outstanding requests sends work to the least busy backend and suits uneven or long requests. Power of two choices compares two random backends and picks the less loaded, balancing well even with many independent balancers. Random is simple and avoids herding. Hashing on a key such as user id keeps a key on one backend for cache affinity, and consistent hashing limits movement when backends change.

Why this question is asked

Every load balancer has to answer one question many thousands of times a second: which backend gets this request? The algorithm it uses decides whether a slow backend gets buried, whether caches stay warm, and whether adding servers actually spreads load. Interviewers ask about the common algorithms to check that we know how each one decides and, more importantly, when each one is the right choice. In this answer, we will go through each algorithm with a concrete situation where it fits, look at the problem of many independent balancers, and finish with a comparison table.

1Round Robin and Weighted Round Robin

Round robin keeps a pointer into the list of backends and sends each new request to the next one, wrapping around at the end. With backends A, B and C, requests go A, B, C, A, B, C. It is cheap, predictable and fair in request count.

It is the right choice when the backends are identical and requests cost about the same, for example a stateless API on identical pods where most calls take 5 to 10 ms. Its weakness is that it balances counts, not work: if some requests are much heavier, a backend can be overloaded while still getting its equal share.

Weighted round robin gives each backend a weight, and backends receive requests in proportion to it. With weights 2, 1 and 1, the first backend receives half the requests. It fits a mixed fleet, such as during a migration when some instances have twice the cores of others.

2Least Connections and Least Outstanding Requests

Least connections sends each new connection to the backend with the fewest open connections. Least outstanding requests, used by many layer 7 proxies, counts requests that have been sent and not yet answered. Both adapt to how long work takes: a backend stuck on slow requests keeps a high count and naturally receives less new work, while a fast backend clears its queue and gets more.

These suit long or uneven requests, such as a service where some calls take 5 ms and others several seconds, or connections that live for very different lengths of time like WebSockets. They need the balancer to track counts per backend, and they behave poorly for brand-new backends, which have zero load and get flooded, so they are often combined with slow start.

3Power of Two Choices and Random

Power of two choices picks two backends at random and sends the request to the one with fewer outstanding requests. That small step gives a surprisingly large benefit: it balances almost as well as checking every backend, but costs only two lookups, and because different balancers pick different random pairs, they do not all pile onto the same backend.

It is the right choice when there are many balancers that each see only part of the traffic, such as client-side balancing in hundreds of service instances, or a large proxy fleet. Envoy's least request policy uses this approach by default.

Plain random selection simply picks any backend. Its balance is worse than round robin in the short run, but it needs no shared pointer or state, and it avoids synchronised behaviour when many balancers decide independently. It is a fine choice for simple client-side balancing with many clients and many backends.

Step throughPower of two choices for one request
  1. Pick two different backends at randomfor example pod 3 and pod 9
  2. Read their outstanding request countspod 3: 4, pod 9: 11
  3. Send to the one with fewerpod 3
  4. Increment its count, decrement when the response returns

4 steps in order. Play them, or step through them one at a time.

4Hashing on a Key and Consistent Hashing

Hash-based balancing computes a hash of a key, such as the user id, session id or client IP, and maps it to a backend, so the same key always lands on the same backend. That is useful for cache affinity: if each backend caches data for the users it serves, sending a user's requests to the same backend gives much higher hit ratios. It is also how layer 4 balancers keep all packets of one connection together.

A simple hash modulo N has a problem: when N changes from 10 to 11 backends, almost every key maps somewhere new, and every cache goes cold at once. Consistent hashing, with a ring of virtual points or Google's Maglev table, moves only about 1/N of the keys when a backend is added or removed. The weakness of any hashing is hot keys: one very active user always lands on one backend.

5Many Balancers and the Herding Problem

Algorithms that choose the 'best' backend from shared information can misbehave when many balancers act independently. If 100 clients each see that pod 4 has the fewest requests, all of them send their next request there in the same instant, and pod 4 is suddenly the busiest. This is herding, and it is why random elements, as in power of two choices or plain random, are valuable in distributed setups.

When each algorithm fits
AlgorithmHow it choosesRight choice when
Round robinnext in turnidentical backends, similar requests
Weighted round robinin turn, by weightbackends of different sizes
Least connectionsfewest open connectionslong-lived or uneven connections
Least outstanding requestsfewest unanswered requestsuneven request cost, one balancer view
Power of two choicesless loaded of two randommany balancers, each with partial view
Randomany backendsimple client-side, many clients
Hash on a keyhash(key) to backendcache affinity, sticky state
Consistent hashinghash ring or Maglev tableaffinity with backends changing

6Follow-up questions

Why can least connections behave badly when there are many independent balancers?

Each balancer only knows the connections it opened itself, so its picture of load is partial, and many balancers can pick the same apparently idle backend at the same moment. Together they flood it, then all move away together, and load oscillates. Power of two choices fixes this by adding randomness, so different balancers pick different candidates, while still avoiding busy backends.

Which algorithm would you choose by default for an HTTP service on Kubernetes?

For a proxy such as Envoy, least request with power of two choices, plus slow start for new pods. It handles uneven request costs well and behaves well with many proxies. Round robin is fine when requests are uniform, and hashing only when there is a real benefit from affinity.

Does sticky session load balancing count as hashing?

Often yes: cookie-based or IP-based affinity sends a client to the same backend each time. Cookie-based stickiness remembers a choice rather than computing it, but the effect and the hot-key risk are the same.

7Conclusion

In this answer, we saw that round robin and weighted round robin balance request counts and suit uniform work, least connections and least outstanding requests follow actual load and suit uneven work, power of two choices balances almost as well as full least-load while avoiding herding among many balancers, random is simple and stateless, and hashing gives affinity, with consistent hashing limiting how many keys move when backends change.

What to say in the interviewAbout 80 seconds aloud

Open with

Round robin sends each request to the next backend in turn. It is cheap and fair in counts, so it suits identical backends with requests of similar cost, like a stateless API on identical pods.

Then, if they want more

Weighted round robin gives bigger instances proportionally more, which helps with a mixed fleet. Least connections, or least outstanding requests in an HTTP proxy, sends work to the backend that is least busy right now, so slow backends naturally get less; I would use it when request costs vary a lot or connections are long-lived.

Power of two choices picks two random backends and sends to the less loaded one; it balances nearly as well as checking all of them, costs almost nothing, and works well when many balancers each see only part of the traffic, because the randomness stops them all piling onto the same backend.

Plain random is the simplest and also avoids that herding. Hashing on a key like user id sends the same user to the same backend, which is great for cache affinity, and consistent hashing, a ring or Maglev, means adding or removing a backend moves only about one Nth of the keys, though hot keys remain a risk.

About this answer

Last updated
13 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the official documentation for the version you use. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Explain how each works and give a situation where each is the right choice.": https://scrivio-interview-library.netlify.app/architecture/load-balancing-networking/b2430bebf2/