A seeded simulation of four continuous-batching replicas: why round robin and request counts fail when request lengths differ by ten times, and what signal each router needs.
Why web load balancing habits fail for model servers
Round robin works well for web servers because requests are roughly the same size. Send every fourth request to each of four servers and each server gets about a quarter of the work. Model servers break that assumption. A request that asks for a 300-token answer and one that asks for a 4,000-token answer differ in work by more than ten times, and the router cannot see the true output length when it decides.
Model servers also do not work like a thread per request. An engine with continuous batching runs many requests together, generating one token for each running request per decode step. A replica admits a new request only when it has room, both in the number of running sequences and in KV cache memory. When there is no room, the request waits in that replica's queue, and the wait is where tail latency comes from.
This guide compares four routing rules on a seeded simulation of four replicas with mixed request lengths, and asks what signal each rule needs from the servers. The simulation uses assumed constants and is labelled as such throughout. It is not a measurement of any serving engine, and its value is in showing mechanisms, not in the exact numbers.
The simulated replica
Each simulated replica follows a simplified continuous-batching model:
- at most 16 requests decode together;
- each decode step produces one token for every running request and takes 10 ms plus 0.5 ms per running request;
- a request is admitted only when its KV reservation, prompt tokens plus maximum output tokens, fits in a 24,000-token budget; otherwise it waits in a FIFO queue on that replica.
Reserving the maximum output up front is a deliberate simplification. Engines built on paged KV memory, as described in the PagedAttention paper, allocate blocks as tokens are generated and can preempt requests under pressure. Reservation makes the simulation deterministic and makes the effect of long requests easy to see, at the cost of overstating how much memory a long request holds early in its life.
The workload is 1,200 requests at three per second. Ninety per cent are short: a 500-token prompt with a 300-token cap. Ten per cent are long: a 2,000-token prompt with a 4,000-token cap. The true output length is uniform between half the cap and the cap, and no router sees it.
Four routers and the signal each needs
- Round robin needs no signal at all.
- Least outstanding requests needs a count of running plus waiting requests per replica.
- Power of two choices picks two replicas at random and sends the request to the one with fewer outstanding requests. It needs the same count, but only for two replicas.
- Least reserved tokens needs the sum of KV reservations, running plus waiting, per replica.
The signal matters as much as the rule. A count of outstanding requests can be kept by the router itself, by counting requests it sent and responses it saw, which is how Envoy's least-request balancer works. A token-based signal is different: the router can compute reserved tokens for requests it sent, but actual KV use depends on how far each request has got, and that lives in the engine. Using it in practice means the replicas must export it, and the router must tolerate it being slightly stale.
The run
The table below is the short-request latency from the companion simulation with seed 3. Every request completes under every router.
router short p50 short p95 short p99 short queue p99 peak waiting on one replica
round robin 3.23 s 33.93 s 41.16 s 37.70 s 35
least requests 2.89 s 4.08 s 16.81 s 14.17 s 5
power of two choices 2.90 s 9.26 s 20.35 s 17.03 s 8
least reserved tokens 3.01 s 4.03 s 4.73 s 0.76 s 2The medians are close: most short requests are served in about three seconds whatever the router does. The tails are not. Under round robin, the 99th-percentile short request takes 41 seconds, and almost all of that, 37.7 seconds, is time spent waiting to be admitted. Short requests that land behind a cluster of long ones on the same replica wait for KV memory to free up, while another replica sits nearly idle.
Counting outstanding requests helps a lot, because a replica with a long queue stops receiving traffic. It still treats a long request and a short request as one unit each, so a replica with three long requests running looks less busy than one with five short ones. The p99 falls to 16.8 seconds, still dominated by queueing.
Power of two choices sits between round robin and full least-requests, as theory predicts. Mitzenmacher's analysis shows that sampling two servers and picking the less loaded one gives an exponential improvement in maximum load over random assignment, and most of the benefit of checking every server. It needs much less state per decision, which matters when there are many routers and many replicas.
Routing by reserved tokens brings the short p99 down to 4.7 seconds, with a queueing p99 under one second. The router is measuring the resource that actually blocks admission, so it stops sending work to replicas whose memory is committed to long requests.
Reading the result honestly
The ranking holds across the three seeds the tests check, but the exact numbers depend on every assumed constant. Change the KV budget, the long-request share or the arrival rate and the gaps change, and at low load all four routers look the same because nothing queues. Treat the table as a picture of the mechanism: when request sizes vary widely and admission is limited by memory, a router that counts requests is blind to the thing that causes waiting.
Several real effects are not modelled. Prefix caching makes some requests much cheaper on a replica that has already seen their prompt prefix, which argues for affinity rather than pure load balancing. Preemption lets an engine pause a long request to admit short ones. Prefill and decode have different costs, and long prompts load a replica before they generate anything. Each of these changes which signal is best.
Implementation notes
A practical rollout usually goes in this order.
- Start with least outstanding requests or power of two choices, which most proxies support and which need no cooperation from the engine.
- Export per-replica queue depth and KV cache utilisation from the serving engine as metrics, and check whether queueing time, not decode time, dominates your tail.
- If it does, move to a router that reads those metrics, and check how fresh its view of them is.
- Keep a fallback. If the metrics feed is stale or missing, fall back to request counting rather than to round robin.
Estimate cost with care. A token-aware router that uses the maximum output tokens as its weight will over-weight requests that set a large cap and stop early. Weighting by a learned or historical output length per route can help, but it is an estimate, and the router should degrade gracefully when it is wrong.
Failure modes
Stale load signals cause herding. If every router sees the same lightly loaded replica in the same scrape interval, they all send to it at once. Power of two choices is more robust here than least-loaded selection, because the random sample spreads the load even when the signal is stale.
Heterogeneous replicas break all four rules. A replica on a slower GPU or with a smaller KV budget needs a weight, or a token count that is normalised by its capacity.
Long-request isolation can be better than routing. If long requests are rare but heavy, a separate pool for them can protect short-request latency more simply than a clever router.
Verification
The companion simulation has five tests: every request completes under every router; the default run matches the table above; the short-request tail ordering of round robin, least requests and least reserved tokens holds for three seeds; the tail under round robin is mostly queueing; and an unknown router name is rejected. It takes about fifteen seconds to run with python -m unittest -v. No serving engine is involved, and no number in this guide is a benchmark.
Run the example yourself
The seeded replica simulation, the four routers and five tests. It is a simulation with assumed constants, not a benchmark of any engine. Companion code on GitHub; its README lists the prerequisites, exact commands, expected output and limits.