Why you are doing this at all
Say you have ten identical servers behind round robin, so each one gets a tenth of the traffic. Now one of them starts taking four times as long per request, because a neighbour on the same host is doing something expensive. Round robin doesn't notice. It keeps sending that server exactly a tenth of the traffic, and the queue in front of it keeps growing. Within a minute, a tenth of your users are timing out, while the other nine servers sit at 40 percent utilisation.
Nothing failed. The load balancer did exactly what it was configured to do.
A load balancer is a guess about which server is least busy, made from readings that are already out of date. Each algorithm guesses from a signal, some measurement of how busy a server is, and every signal has an age. Round robin uses no signal at all. Least-connections uses a count from microseconds ago. An active health check, a probe the balancer sends on a schedule, uses a result from up to one probe interval ago. DNS (the Domain Name System) uses an answer from up to one TTL ago. The TTL, or time to live, is how long a client may keep using a DNS answer before it asks again.
So every algorithm here is a different bet on how stale its signal is, and on what that staleness costs. And every interesting failure happens at the same moment: the signal stops being merely old and starts pointing the wrong way. Take a server that answers every request with an instant error. It has no open connections and the best response time in the fleet. So the two cleverest common algorithms, least-connections and least response time, both send it more traffic than any other server. That isn't a bug in the code. The signal has inverted, and the worst server now looks like the best one.
Three jobs, not one
"Load balancing" covers three jobs that people mix up, and a design should say which ones it's doing.
Spreading load, so no server is much busier than the others. This is what most people mean by the term, and it matters least of the three.
Removing failures, so a broken server stops getting traffic. This is arguably the more valuable job. It also fails in the most dramatic ways, because a mechanism that can remove servers can remove all of them.
Shaping traffic, which covers sticky sessions, canary routing, weighted rollouts, rate limiting and steering users by geography. A sticky session keeps each user on the same server. Canary routing sends a small share of traffic to a new version first. This job is policy rather than balance, and it's often the reason the load balancer exists at all.
When you do not need one
If you have one server, you don't need a load balancer. You need a second server. If your requests are uniform, your servers are identical and your fleet is small, round robin is fine, and anything cleverer is wasted effort. And if your real problem is one slow endpoint, choosing between load balancing algorithms only changes where the slow requests go. It doesn't make the endpoint faster.
The toolkit
Where the decision happens
There are five places the decision can happen, and each can only balance what it can see. L4 and L7 are layers of the network model. At L4, the transport layer, a balancer sees connections. At L7, the application layer, it sees each HTTP request. Anycast advertises one IP address from many locations, and BGP, the internet's routing protocol, sends each client to the nearest one. In a service mesh, a small proxy runs beside every client and does the balancing there.
| layer | decides per | information | the catch |
|---|---|---|---|
| DNS | client resolution | none, effectively | clients cache past your TTL, and some ignore it entirely |
| anycast, BGP | network flow | routing distance | closest by BGP is not closest by latency, and withdrawal is slow |
| L4, transport | connection | connection counts | it cannot see requests, which matters more than it sounds |
| L7, application | request | everything in the request | terminates TLS, costs CPU, is a tier you now operate |
| client-side or mesh | request | the freshest possible | every client health-checks every server, so the probe traffic is N times M |
The L4 row is the trap in that table, because it breaks modern services without raising any error.
An L4 load balancer picks a backend when a connection opens, and every request on that connection goes to that backend until the connection closes. With HTTP/1.1 and short connections, that's roughly fine. HTTP/2 and gRPC multiplex, which means they send many requests over one long-lived connection. With them, an L4 balancer isn't balancing at all. If ten clients connect, ten backends are in use, however many you've deployed.
The gRPC documentation names two fixes. One is to put an L7 proxy in the path, so the decision happens per request. The other is client-side load balancing: each client discovers all the backends, opens connections to them, and picks one per call.
L4 and L7 together, which is what production actually looks like
The table reads like a choice, but it's usually a stack. Most serious setups run both, one behind the other, because each is good at different things.
An L4 balancer reads a packet's addresses and ports and forwards it. It doesn't terminate TLS (Transport Layer Security), which means it never decrypts the traffic. It doesn't parse HTTP, and it doesn't buffer a request body. In some designs the reply skips the balancer entirely and goes straight from the server to the client, which is called direct server return. The work per connection is close to constant, so one box can handle an enormous amount of traffic. That makes it the place to absorb a volumetric flood, an attack that tries to overwhelm you with sheer volume.
An L7 balancer terminates TLS, parses the request, and can decide based on the path, a header or a cookie. Every one of those steps costs CPU, and the TLS handshake costs the most. You size this tier in requests per second per core, and it's something you scale, monitor and get paged for.
So the usual shape is an L4 tier in front of an L7 fleet. On the clouds, that's a network load balancer in front of an application load balancer. Elsewhere, it's hardware or kernel-bypass forwarding in front of a fleet of Envoy proxies. Kernel-bypass forwarding is software that handles packets without going through the operating system's network stack. The L4 tier gives you a stable address, absorbs volume, and spreads connections across the L7 instances. The L7 tier makes the decisions that need the request, which the L4 tier can't see.
The dividing line is what the decision needs to see. If a decision needs only addresses and ports, it belongs at L4, where it's nearly free. If it needs the request, it belongs at L7, where you pay for it. A decision at the wrong layer goes wrong in one of two ways. In the first, an L7 tier does work that an L4 tier would have done for a fraction of the cost. In the second, you get the gRPC failure above: the decision is made at a layer that can't see the thing it's deciding about.
The algorithms, in order of how much they know
Round robin. The balancer sends each request to the next server in the list. It uses no signal, so it can never be misled. Its weakness isn't that it's simple. It assumes every request costs the same and every server is equally fast, and both assumptions are usually false.
Weighted round robin. This is round robin with fixed weights, so a bigger server takes a bigger share. It's fine for permanent differences, like instance size. It does nothing for temporary differences, and those are the ones that come and go.
Random. For uniform requests, random works out the same as round robin on average. It keeps no state, so any number of load balancers can use it without coordinating. When several independent balancers each run round robin, the combined result is effectively random anyway.
Least connections, or least outstanding requests. The balancer sends each request to the server with the fewest requests in flight, meaning started but not yet finished. This is the first algorithm that uses a real signal, and it fixes the opening example. The slow server builds up in-flight requests, so it looks busy and gets avoided. It's a good algorithm, and it has one failure mode, covered below.
Least response time, usually an exponentially weighted moving average. The balancer tracks each server's recent latency and prefers the fastest. An exponentially weighted moving average (EWMA) is an average that counts recent samples more than old ones. This beats counting connections when requests differ in cost. Its weakness is that the signal is always seconds old, because an average smooths out changes, and smoothing means delay.
Power of two choices. The balancer picks two servers at random and sends the request to the less loaded one. The result is much better than it sounds.
Consistent hashing and Maglev. These route by a key, so the same key always lands on the same server. That's a different goal: affinity, keeping related requests on one server, rather than balance. The consistent hashing article covers both properly, including why the ring needs virtual nodes and why a lookup table beats it at high request rates.
The power of two choices
Here's a result that sounds too good to be true, and is true.
Say each request goes to one server picked at random. Then the queue lengths across your fleet have a tail that decays geometrically. At a given load, the fraction of servers with at least k requests queued shrinks like a constant raised to the power k, which is slowly. Now pick two servers at random, and send the request to whichever has the shorter queue. The tail becomes doubly exponential: the fraction with at least k queued shrinks like a constant raised to the power 2^k.
This is Mitzenmacher's result. In his model, requests arrive at random, as a Poisson stream, and each one samples d servers at random and joins the shortest queue. For d = 1, the tails decay geometrically. For any d of 2 or more, they decay doubly exponentially. One extra sample changes the shape of the distribution, not just a constant in it.
Fraction of servers with at least k requests queued. One random choice P = 0.9^k Two random choices P = 0.9^(2^k − 1) k one choice two choices ──────────────────────────────────────── 1 90.0% 90.0% 2 81.0% 72.9% 3 72.9% 47.8% 4 65.6% 20.6% 5 59.0% 3.8% 6 53.1% 0.13% 7 47.8% 0.00015% ... 10 34.9% about 1 in 10^47 20 12.2% about 1 in 10^48,000 Read the k = 10 row again. With one choice, a third of your fleet has ten or more requests queued. With two, that queue length effectively does not occur. The cost of the improvement: one extra counter read per request. No coordination, no shared state, no configuration.
Two things to note. First, the two choices have to be random. If you compare the two least loaded servers you know about, you get a different and worse algorithm, because every balancer then piles onto the same server. Second, the reason it works isn't obvious. A purely random choice sometimes picks the worst server in the fleet. With two choices, that only happens when both samples are bad, which is quadratically less likely: a 1 in 10 chance becomes 1 in 100. You aren't finding the best server. You're reliably avoiding the worst one.
When the signal inverts
Now for the failure that makes least-connections and least response time dangerous. If you remember one failure from this topic, make it this one.
Say a server develops a fault and starts returning 500 in 1 millisecond, instead of serving a real response in 100. Here is how each algorithm sees it.
Its count of outstanding requests is zero, because it finishes each one instantly. Least-connections concludes that it's the idlest server in the fleet.
Its average response time is 1 millisecond, 100 times better than any other server. Least response time concludes that it's the fastest server available.
So both algorithms send it as much traffic as they can, and the healthy servers get less. The cleverer the algorithm, the more of your traffic it sends into the broken server. Round robin knows nothing, and it would have limited the damage to one server's share.
Every fix comes down to one rule: never score a failure as a success.
Count only successful responses in the latency average. A 500 isn't a fast response. It's no response at all.
Count an error as an outstanding request that never completed, or better, weight it as expensive. Then failing fast makes a server look busy rather than idle.
Add outlier detection, sometimes called passive health checking. The balancer watches real traffic and ejects any server whose error rate is far above its peers'. This is strictly better than active probing, because it measures the real request path with real requests.
Health checks, and the day they all fail
There are two kinds of health check, and they differ in which traffic they measure.
Active health checks are probes the balancer sends on a schedule. Their result is up to one interval old. They also have a specific and very common failure: the probe path isn't the request path. A /health endpoint that always returns 200 reports a server as healthy while every real request throws an error. If the check doesn't exercise the dependencies that real requests need, it only tells you the process is running, and you knew that already.
Passive health checks, also called outlier detection, watch real responses. They're fresher and cheaper, and they measure the thing you care about. The catch is that a server with no traffic produces no signal, so you usually want both kinds.
The next failure can take down more at once than any other in this topic. Say your health check verifies a database connection, and the database has a brief problem. Every server fails its check at the same moment. The load balancer does exactly its job and removes every server from rotation. Now you have a complete outage, from a fleet that could mostly have served traffic, and the load balancer caused it.
Envoy, a widely used open-source proxy, ships the answer, and it's worth knowing by name. Envoy has a configurable panic threshold, 50 percent healthy by default. When the share of healthy hosts falls below it, Envoy stops honouring health status and balances across all hosts. Its documentation gives the reason: to avoid a situation where host failures cascade through the cluster as load increases. The reasoning goes like this. If most of your fleet looks broken, the likelier explanation is that your health signal is broken. And sending traffic to servers that may be degraded beats sending it nowhere.
The general rule applies well beyond Envoy: any mechanism that removes capacity needs a floor. That covers ejection, circuit breaking, outlier detection and scaling down. Circuit breaking stops calls to a dependency that keeps failing. Each of these should refuse to act past some proportion of the fleet, because removing too much always does more damage than keeping something broken.
Adding and removing servers, which is when the signal is worst
Everything so far assumes the set of servers stays the same. When that set changes, the balancer knows least, and both directions have a specific failure.
A new server has no history at all. Its signal isn't stale, because it has none. Its caches are empty, its just-in-time (JIT) compiler hasn't compiled any hot code yet, and its connection pools aren't open. If you send it a full share straight away, it will be several times slower than its peers. If the fleet is already busy, it can saturate and fall over before it warms up. So you get an outcome nobody expects: adding capacity to a loaded fleet makes things briefly worse.
Fleet of 10, 10,000 req/s, adding an 11th instance.
Immediate share, round robin 10,000 / 11 = 909 req/s
Warm instance
95% cache hit at 1 ms, 5% miss at 50 ms
average latency = 3.5 ms
in flight 909 x 0.0035 ≈ 3
Cold instance, same traffic
20% cache hit at 1 ms, 80% miss at 50 ms
average latency = 40 ms
in flight 909 x 0.040 ≈ 36
if its worker pool holds 32
→ saturated on arrival, queueing immediately,
and its health check may now fail
With a slow start ramp over 60 s
first share 909 x 0.02 ≈ 18 req/s
in flight 18 x 0.040 ≈ 0.7
→ it warms while doing real but survivable work,
and reaches full share already fast
Least-outstanding-requests helps here by accident, because a
cold instance accumulates in-flight requests and gets
avoided. Round robin does not notice at all.The fix is a slow start, or warm-up ramp. A newly healthy server gets a small fraction of its share at first, and the share grows over a window, typically tens of seconds. Envoy calls this slow start mode. Least-outstanding-requests gives you some of this for free, because a slow, cold instance looks busy. This shows why an algorithm that measures something beats one that measures nothing.
A removed server still has work in flight. If you take it out of rotation and kill the process, every request it was serving fails. The right order is to stop sending it new requests, wait for the in-flight ones to finish or hit a deadline, and then shut it down. That's connection draining, and the number of requests it saves is easy to underestimate.
A warm instance has about 3 requests in flight, from the worksheet above. A deploy that cycles 10 instances then drops about 30 requests. Ten deploys a day is about 300 failed requests a day, caused entirely by deploying. They show up as a low background error rate that nobody can reproduce, because it follows deploys rather than traffic. Draining removes all of it, and it costs one configuration value: how long to wait before giving up on the stragglers.
When to stop guessing
Everything so far is the balancer trying to work out each server's load from outside. There's a better source for that, and it's the server itself.
The server knows its queue depth, its CPU use, its own latency, and whether its dependencies are answering. Nothing outside it can know those things sooner or more accurately. So past a certain load, the right design stops asking "which server is least busy?" and lets servers say no. That's backpressure: a server refuses work it can't finish in time, and the caller backs off or goes elsewhere.
Two mechanisms carry most of the value.
A concurrency limit, which doubles as a latency guarantee. A concurrency limit caps how many requests a server works on at once. Little's Law says the number of requests in a system equals the arrival rate times the time each one spends there. Turn it around. If a server completes C requests a second and you cap the number it works on at K, nothing waits longer than K / C. So the limit isn't an arbitrary safety number. It's your latency target, in the only unit the server can enforce.
Server completes 1,000 requests/s. Little's Law: L = arrival x W,
so at the limit, wait = concurrency / completion rate.
concurrency limit worst wait verdict
─────────────────────────────────────────────────────────
100 100 ms comfortable
200 200 ms a sensible target
1,000 1.0 s equals a typical
client timeout
5,000 5.0 s every response
arrives unwanted
unlimited unbounded the default
So choose the limit from the target, not from a guess:
limit = completion rate x acceptable wait
= 1,000 x 0.2 s = 200
Everything above that limit gets rejected immediately,
which costs almost nothing, instead of queued, which costs
a slot that a live client could have used.Adaptive limits, because you can't know C in advance. A server's real completion rate changes with the request mix, the cache state and the neighbours on its host. Netflix's concurrency-limits library borrows the idea from congestion control in TCP (the Transmission Control Protocol), which has been solving this exact problem for decades. It has limit algorithms based on TCP Vegas, on latency gradients, and on additive-increase-multiplicative-decrease (AIMD), which raises the limit slowly and cuts it sharply. The server watches its own latency and lowers its concurrency limit when latency starts rising, because rising latency means a queue is forming. The library's stated goals are to avoid cascading failures and to stop anyone having to guess the limit by hand.
Why deep queues are worse than rejection
All of this matters because queueing has a cliff in it, and the cliff arrives sooner than people expect.
Say a client gives up after one second. Then any response produced after one second is work done for nobody. It used a worker, a database query and a connection, and its result went into a closed socket. So once the queue is deeper than your completion rate times the client timeout, throughput doesn't just drop. It disappears. Every request waits longer than the timeout, so every completion is wasted, and the server is 100 percent busy doing nothing useful.
Server capacity 1,000 req/s
Client timeout 1 s
Arrival rate during the incident 1,500 req/s
Queue grows at 1,500 − 1,000 = 500/s
Waste begins when the wait exceeds the timeout,
which is a queue of 1,000 x 1 s = 1,000
time to that queue depth 1,000 / 500 = 2 seconds
After 2 seconds of 1.5x overload, every new request is
answered after its client has given up. A second later,
useful throughput is zero. CPU: 100 percent.
────────────────────────────────────────────────────────
You have 2 seconds. No human is in that loop, so the
queue cap has to be configured in advance:
max queue = capacity x client timeout = 1,000
and everything past it is rejected in microseconds.The method
1. Say which of the three jobs you're buying. Spreading load, removing failures, or shaping traffic. Most designs need all three and describe only the first.
2. Choose the layer, and check the protocol first. If it's HTTP/2 or gRPC, an L4 balancer isn't balancing. That check takes five seconds and saves a week.
3. Choose the algorithm from how uniform things are. If the servers are identical and the requests are uniform, round robin is fine. Otherwise, use power of two choices. It's the sensible default, and it costs one extra counter read.
4. Say what happens when a server fails fast. Name success-filtered scoring and outlier ejection. If your answer is "the health check catches it", say how long that takes.
5. Put a floor under everything that removes capacity. That means ejection, circuit breaking and removal by health check. Name the proportion at which each one stops trusting itself.
6. Set a concurrency limit from the latency target, and reject past it. limit = completion rate x acceptable wait. Then reject rather than queue, because every response from a queue deeper than that arrives after its client has given up.
Worked examples, start to finish
Here are four systems. In each one, the obvious approach fails in a different way: a protocol mismatch, a stale assumption, an inverted signal, and a queue that outlives its clients.
A gRPC service where nothing is balanced
An internal gRPC service runs on 100 pods, behind the cloud provider's network load balancer. It works, and then under load a handful of pods saturate while most sit idle. The load balancer's own metrics report a perfectly even distribution.
Both readings are true. The balancer is spreading connections evenly, and there are far fewer connections than requests, because gRPC multiplexes. Each client opened one connection, was assigned one pod, and has sent every request to that pod ever since.
You have two options, and the choice comes down to who runs the balancing logic. One is to put an L7 proxy in the path, so a balancing decision happens per request and you can use any algorithm above. The other is client-side load balancing, where each client resolves the full list of backends and picks one per call. That gives the freshest possible signal and no extra network hop. The cost is that every client needs the logic, and every client health-checks every server.
The sign to remember: if the balancer reports an even distribution and the pods disagree, you're balancing the wrong unit.
A fleet that is not uniform, which is all of them
Take a stateless HTTP service on 40 identical instances, behind round robin. Except they aren't identical. They run on shared hosts with noisy neighbours, a few run an older build, and two have cold caches after a restart. Requests take anywhere from 5 milliseconds to 800, depending on the endpoint.
Round robin ignores all of that. The result isn't a catastrophe. It's a p99 that stays worse than the fleet could deliver, where the p99 is the latency that 99 percent of requests beat. It stays worse because at any moment the slowest instance is getting its full share and building a queue.
Round robin, and add capacity when the p99 is bad
This is the default, and it survives because it works: nothing is broken, the mean is fine, and the p99 is only disappointing. So teams usually respond by adding instances. That lowers every instance's load, the slow one's included, and so it improves the p99 without fixing whatever made one instance slow. It works, and it's the most expensive fix available.
Least outstanding requests
Route each request to the instance with the fewest requests in flight. A slow instance builds up in-flight requests on its own, so it stops getting new ones without anyone configuring anything. The mechanism adapts to causes you never listed: noisy neighbours, cold caches, a bad build, an expensive request that happened to land there.
The cost: it needs a count per instance, so it reflects one balancer's view rather than the whole fleet's. With several balancers, each keeps its own count, and they can all pick the same instance and overload it. It also has the inversion problem, so it needs success-filtered scoring, which the next example covers.
Two random samples, and stop trying to find the best server
Question the premise that you want the least loaded server. You don't, and chasing it is what makes setups with several balancers collide: each one independently picks the same idlest instance and sends it a burst. The goal is never to pick the worst one.
So sample two at random and take the better one. The tail goes from geometric to doubly exponential, and the worksheet above makes that concrete. At 90 percent load, one choice leaves a third of the fleet with 10 or more requests queued, and two choices make that queue length practically never happen. Two independent balancers can't herd, because neither is aiming at the single best server.
Size the cost: one extra counter read per request, with no shared state, no coordination and no setting to tune. Few changes in load balancing buy as much for as little, and it's why most modern proxies use it by default or offer it.
You give up very little, and this trade is unusually one-sided. The real caveat is that it doesn't fix an instance that is broken rather than busy, and it doesn't remove anything from rotation. Balance and failure removal are separate jobs, and two choices does only the first.
One server failing fast
Take the same fleet. One instance starts returning 500 in a millisecond, because a config push gave it a bad credential. It isn't down. It answers immediately, and wrongly.
Least outstanding requests, which you've just deployed, sees an instance with zero requests in flight and decides it's idle. It sends that instance everything it can. Under round robin your error rate would have been 2.5 percent, and now it's nearly 100 percent. The cause is an improvement you made on purpose.
40 instances. 39 healthy at 100 ms. 1 returning 500s in 1 ms.
Traffic 4,000 req/s.
Round robin
the faulty instance gets 4,000 / 40 = 100 req/s
failed requests = 100/s
error rate = 2.5%
Least outstanding requests, no success filter
healthy instance, in flight 100 ms x load ≈ 10 each
faulty instance, in flight 1 ms x load ≈ 0.1
→ it looks 100x idler than every peer
→ it receives requests until its in-flight count
matches, which at 1 ms per request means
about 100x the share of a healthy instance
failed requests most of the 4,000/s
error rate up to ~99%
────────────────────────────────────────────────────────
Same fault, same fleet. 2.5% against 99%, and the
difference is that one algorithm used information and
the signal had inverted.
With success-filtered scoring, an error counts as neither a
completed request nor a fast one, so the faulty instance
looks maximally busy and is avoided. Outlier ejection then
removes it in seconds rather than milliseconds.Rely on the health check to catch it
This is the natural first answer, and it isn't wrong, only slow. The check will fail and the instance will be removed, but that takes up to one probe interval for each consecutive failure you require. With a 5 second interval and 3 required failures, that's up to 15 seconds. Meanwhile, least outstanding requests sends the instance as much traffic as it can take, so those 15 seconds hold most of your errors for the day. The mechanism works on the wrong timescale. The balancer makes a routing decision in milliseconds, and this takes seconds, three orders of magnitude longer.
Score only successes, and add outlier ejection
These two changes work at different speeds, and you want both. Success-filtered scoring works per request. An error counts as neither a completed request nor a fast one, so the faulty instance looks fully busy straight away. The algorithm stops choosing it within milliseconds, without removing anything. Outlier ejection then watches real error rates and takes the instance out of rotation within seconds, so it stops getting even its round robin share.
The cost: outlier ejection removes capacity, so it needs a floor. Its thresholds also need to tell a broken instance apart from one that got unlucky with expensive requests. If you make it too sensitive, a normal latency spike ejects half the fleet.
Let the instance remove itself, and treat the error as data
Question the premise that the balancer should be the one to notice. It's the worst-placed component to do it, because it sees responses while the instance sees the cause. An instance that can't reach a dependency, has a bad credential or has lost its config knows that directly and at once. A readiness check is the check a balancer uses to decide whether to send an instance traffic. The instance can fail its own readiness check, or return an explicit "don't send me traffic" signal, before a single user request is harmed.
So turn it around. Make a failing dependency a readiness state that the instance reports, rather than a symptom the balancer infers from error rates. Detection time drops from seconds of sampling to zero, because there's nothing to sample.
Size the benefit with the numbers above. At 4,000 requests a second, compare an instance that removes itself on its first failed dependency check with a balancer that infers the fault over a 15 second window. That's the difference between roughly zero failed requests and tens of thousands.
The cost is real. Every instance can now take itself out of service, so a bug in that logic causes an outage rather than a slowdown. It needs the same floor as everything else, applied on the balancer side: if too many instances declare themselves unready at once, the balancer ignores them. Self-reporting is a better signal, but it isn't more trustworthy.
The decision: score only successes, add outlier ejection with a floor, and where you control the server, let it declare its own readiness. The floor works like the panic threshold in the health check section.
The overload that gives you 2 seconds
Traffic rises 50 percent because a partner started retrying. Capacity is 1,000 requests a second, arrivals are 1,500 a second, and the client timeout is one second.
The worksheet in the toolkit covers this case. The queue grows by 500 a second and passes 1,000 after 2 seconds. From then on, every request that arrives is answered after its client has given up. A second later, the last on-time response has gone out, and the server runs at 100 percent CPU producing nothing useful. Worse, the clients that timed out retry, so arrivals go up again. That's a retry storm on top of an overload.
Nobody diagnoses and fixes this in 2 seconds, so the defences have to be in place beforehand.
A generous queue, so nothing is dropped
The instinct is that dropping a request is a failure and queueing it is service, so a large queue looks generous. It's the opposite. A request queued past its client's timeout is certain to fail, and it held a slot a live client could have used. A deep queue turns a partial outage into a total one. It also hides the overload from your metrics, because throughput looks fine right up to the point where goodput is zero. Goodput is the rate of responses that arrive in time to be used.
A queue cap from the timeout, and fast rejection past it
Cap the queue at capacity times the client timeout, and reject anything beyond it with an immediate error the client can act on. Now, under a 1.5x overload, two thirds of requests succeed normally and one third fail instantly. That's far better than every request failing slowly. Add a retry budget so the rejected third can't triple your arrivals. A retry budget caps retries as a percentage of total traffic, rather than per request.
The cost: you need to know your capacity, and it isn't constant. The staff tier deals with that.
Let the server discover its own limit, and shed by priority
There are two premises to question. The first is that capacity is a number you can measure once and configure. It isn't. It moves with the request mix, the cache state, the neighbours and the latency of dependencies. So any fixed limit is wrong most of the time, and badly wrong now and then.
So make the limit adaptive. Netflix's concurrency-limits library takes the algorithms of TCP congestion control, which has solved this exact problem for almost 40 years, and applies them to request concurrency. The server watches its own latency, and when latency starts rising, it lowers the limit, because rising latency is what a forming queue looks like from inside. The server finds its own capacity all the time, and nobody has to guess it.
The second premise is that every request deserves the same treatment when you shed load, meaning drop requests on purpose. They don't. Classify traffic in advance, and shed what's cheapest to lose first: background sync before interactive reads, prefetches before user actions, retries before first attempts. Size the benefit. If 30 percent of your traffic can wait, shedding by priority absorbs a 1.4x overload with no failures that users can see.
What you give up: the classification has to exist and be kept up to date. Every new endpoint needs a priority, and an endpoint without one falls into some default class. That's real ongoing work, and it's why teams usually reach this tier after an incident rather than before one.
Where it goes wrong
These are ordered by how often each one turns up.
1. Round robin on non-uniform work
This is the most common mistake and the least dramatic. It shows up as a p99 that is worse than your fleet can deliver. If requests vary in cost or servers vary in speed, round robin spreads requests evenly and load unevenly. Power of two choices costs one counter read and fixes most of it.
2. An L4 balancer in front of HTTP/2 or gRPC
This one is covered above. The sign is a balancer reporting an even distribution while a few pods saturate. Check the protocol before you check anything else.
3. Scoring failures as success
This is the inversion. Any algorithm that measures speed or requests in flight will rank a fast-failing server first. Score only successes, and add outlier ejection.
4. Health checks that do not exercise the request path
A /health endpoint that always returns 200 tells you the process is running, and the TCP connection already told you that. If it doesn't touch the dependencies that real requests need, it will report healthy all through an outage.
The opposite mistake happens too. A health check that touches everything fails whenever any dependency has a hiccup. Then it fails on every server at once, which is the next item.
5. No floor on capacity removal
Health-based ejection, outlier detection and circuit breaking all remove servers, so all three can remove every server. Envoy's panic threshold, 50 percent by default, exists for exactly this. Its documentation says why: to stop host failures cascading as load increases. Whatever your stack, the rule is the same. Past some proportion, a mechanism that removes capacity should conclude that it's the one that is wrong.
6. Queueing past the client timeout
This is the two-second cliff. Once the queue is deeper than capacity times the client timeout, every response arrives unwanted, and the server is at 100 percent CPU. Cap the queue and reject past the cap. A rejection costs almost nothing, while a queued request holds a slot that a live client could have used.
7. Retries with no budget
Retries multiply your load, and they do it exactly when you have the least spare capacity. The arithmetic is worse than it feels, so do it once.
Base traffic 1,000 req/s, capacity 1,000 req/s. Policy: up to 3 attempts per logical request. Attempts per logical request, at failure rate f 1 + f + f² f = 0 healthy 1.00 attempts 1,000 req/s f = 0.2 mild trouble 1.24 1,240 req/s f = 0.5 half failing 1.75 1,750 req/s f = 1.0 everything failing 3.00 3,000 req/s Now add a 1.4x traffic increase on top, at f = 1 1,400 base x 3 attempts = 4,200 req/s against a capacity of 1,000 req/s → a 1.4x problem has become a 4.2x problem The retry policy was correct per request. Every request tried three times, which is reasonable. The amplification is emergent, because each request decides alone and none of them can see the aggregate. With a retry budget capping retries at 10% of traffic worst case arrival 1,400 x 1.10 = 1,540 req/s → 1.54x instead of 4.2x, from one shared counter Retries exist to survive an isolated failure. A budget is what stops them from causing a systemic one.
The fix is a retry budget. It caps retries as a fraction of total traffic, typically a few percent, so retries can help with an isolated failure but can't amplify a systemic one. Per-request limits can't do this, because every request decides on its own to retry, and none of them can see the total.
8. Sticky sessions used to cover for state
Session affinity, keeping each user on the same server, is a legitimate tool for cache locality. It's also often a workaround for servers holding state they shouldn't. And it has real costs. You can't balance freely, and a server's death takes its users' sessions with it. The more sticky your sessions are, the more a deploy disrupts users. If you need affinity for correctness rather than performance, the problem is the state, not the balancer.
9. Treating DNS as a failover mechanism
DNS is a discovery mechanism, and its caching is out of your control. Clients ignore TTLs, resolvers extend them, and connection pools hold addresses for as long as they hold connections. So a server removed from DNS keeps getting traffic for far longer than the TTL suggests. Use DNS for coarse steering, by geography or by tier. Don't use it for a failure that needs handling in seconds. The replication article has a failover budget in which waiting on DNS takes 92 percent of the time to recover.
If you memorise nothing else
| fact | why it matters |
|---|---|
| A load balancer is a guess from stale information | every algorithm is a bet on how stale |
| Round robin distributes requests, not load | requests differ in cost, servers differ in speed |
| Two random choices makes the tail doubly exponential | one extra counter read, no coordination, no tuning |
| At 90 percent load, one choice leaves a third of servers 10+ deep | two choices makes that queue length not occur |
| Pick two at random, not the two you think are best | aiming at the global optimum makes balancers herd |
| A fast-failing server looks idle and fastest | least-connections and least-latency both prefer it |
| Score only successful responses | an error is not a fast response, it is no response |
| L4 plus HTTP/2 or gRPC is not load balancing | one connection, one backend, thousands of requests |
| A health check is a mechanism for removing all servers | put a floor on it. Envoy's default is 50 percent |
| Passive outlier detection beats active probing | it measures the real path with real requests |
| A concurrency limit is a latency guarantee | limit = completion rate x acceptable wait |
| Queue deeper than capacity x timeout produces zero goodput | not less. Zero, at 100 percent CPU |
| A 1.5x overload gives you about 2 seconds | so the cap must be configured before the incident |
| Retry budgets, not per-request retry limits | per-request limits cannot prevent amplification |
| Capacity is not a constant, so limits should adapt | this is TCP congestion control, reused |
What is expected at each level
Mid-level
Know the difference between L4 and L7, and what each can see. Name round robin, least connections and consistent hashing, and say what each is for. Know that health checks exist, and that a server that fails them is removed from rotation.
You aren't expected to raise power of two choices, signal inversion or concurrency limits unprompted. You are expected to answer sensibly when asked. Suppose you're asked what happens when a server is slow but not down. "Round robin would keep sending it traffic, so I'd want something that notices, like least connections" is a good mid-level answer.
The mistake to avoid is describing only the spreading job. Say what happens when a server fails, every time.
Senior
You drive this discussion, and three things must come up without prompting.
The protocol, before the algorithm. If the service speaks gRPC or HTTP/2, say that an L4 balancer will pin each connection to one server, and that you need L7 or client-side balancing. Missing this is the most costly senior-level error in the topic, because the balancer's own metrics don't show it.
An algorithm with a reason attached. Don't give a list. Say what varies in your fleet, and choose from that. Power of two choices as the default, with a one-line reason, reads much better than a list of every algorithm.
What happens to a server that fails fast. Name the inversion and name the fix. This question follows any mention of least-connections. Naming the fix is a much better answer than "the health check would catch it", which is true but takes a full interval.
Disqualifying: no answer for a server that is degraded rather than dead, and treating DNS as a failover mechanism.
Staff+
The focus shifts from choosing an algorithm to deciding how much the balancer should be responsible for at all.
Move the decision toward the server. The balancer is guessing at something the server knows. Concurrency limits, adaptive limits and backpressure give a better signal than any estimate from outside, and saying so changes the whole problem for the better.
Put a floor under every mechanism that removes capacity. That covers ejection, circuit breaking, removal by health check and scaling down. Name the proportion at which each one stops trusting itself, because removing too much always does more damage than keeping something broken.
Calculate the queue cap, and say how long the incident gives you. The cap is capacity times client timeout, and the arithmetic shows the cliff arrives within seconds. This turns "shed load" from a wish into a design.
Classify traffic before you need to shed it. You can only shed by priority if somebody assigned priorities in advance, and keeping them assigned is ongoing work. Say who owns it.
And say what you would not build. Each of these can cost a team a quarter.
You don't need a custom load balancing algorithm, because power of two choices is one counter read and ships in most modern proxies. You don't need a global load-state service so that balancers can agree on the least loaded server. That's a coordination problem built to solve something two random samples already solve. And you don't need an elaborate active health checking system, because passive outlier detection measures the real path for free.
Don't use sticky sessions to work around state that should move out of the server. Don't tune a retry policy per call site, because it can't limit amplification the way one shared budget can. And don't add a second load balancer tier to fix a distribution problem whose real cause is an L4 balancer in front of gRPC.
Sources
Every number attributed below to a paper, project or vendor comes from that published source. The article works out the queue, concurrency and error-rate arithmetic itself, with its inputs stated.
- The Power of Two Choices in Randomized Load Balancing, Michael Mitzenmacher, IEEE Transactions on Parallel and Distributed Systems, 2001. The supermarket model, and the central result that for
dat least 2 the queue length tails decay doubly exponentially while ford = 1they decay only geometrically. - Panic threshold, Envoy documentation. The default 50 percent threshold, and the behaviour of disregarding health status and balancing across all hosts below it. The stated purpose is avoiding a situation where host failures cascade through the cluster as load rises.
- gRPC Load Balancing and gRPC on HTTP/2, gRPC blog. Why a transport-level balancer chooses a backend once per connection and therefore does not balance multiplexed requests. Also the two remedies: a request-aware proxy, or client-side load balancing against a discovered backend list.
- Netflix/concurrency-limits and Performance Under Load, Netflix. Applying TCP congestion control algorithms to request concurrency, including Vegas, latency-gradient and additive-increase-multiplicative-decrease variants. A service then discovers its own limit rather than having one configured. The stated aims are avoiding cascading failure and removing the manual guess.