Round robin is the first load balancer everyone learns. Request one goes to server one, request two goes to server two, and so on. It is fair, it is simple, and for most web services it is good enough.
For LLM inference, it can cost you close to half your throughput.
The team behind SGLang, the engine xAI uses to serve Grok, showed the numbers in a talk. Same GPUs, same model, same traffic. The only change was how requests were routed.
| Routing | Cache hit rate | Throughput |
|---|---|---|
| Round robin | 20% | 82,665 tokens/sec |
| Cache-aware | 75% | 158,596 tokens/sec |
That is 1.9x more tokens out of hardware you already paid for. No new GPUs, no new model, no quantization. Just a smarter decision about which machine gets which request.
This post is about why that works, and what I learned building a small version of it.
The thing round robin doesn't know
In my last post I worked out how expensive the KV cache is. Every token in a prompt leaves about 131 KB of notes on the GPU for a model like Llama 3.1 8B, so the model doesn't have to re-read the conversation for every new token.
Here is the part that matters for routing. Those notes don't have to be thrown away when the request finishes.
Think about what real traffic looks like:
- Thousands of users hit the same product, so they share the same long system prompt.
- A chat is many requests in a row, and each one starts with the entire previous conversation.
- An agent calls the model again and again with the same tools and instructions on top.
In all three cases, most of the prompt is something a GPU has already processed. If the request lands on that GPU, it can skip straight to the new part. This is called prefix caching, and SGLang's version of it stores the cached prompts in a radix tree so it can find the longest match quickly.
But the cache lives on one specific GPU.
Round robin has no idea which one. It just takes turns.
What that looks like in practice
Say you have two GPUs and two popular prompts, A and B.
GPU 1 has served prompt A, so it has A cached. GPU 2 has B cached.
Four requests arrive: A, B, A, B.
With round robin, there is a good chance the second A goes to GPU 2 and the second B goes to GPU 1. Both GPUs now have to process a long prompt from scratch that the other GPU already had ready.
Nothing is broken. Every request succeeds. Your dashboards look healthy. You are just doing the same work twice, all day, on the most expensive machines you own.
Scale that up to dozens of GPUs and hundreds of prompts, and round robin gives you a cache hit rate around 20%. Four out of five times, the work that was already done somewhere gets done again somewhere else.
Cache-aware routing
The fix is to let the router remember.
The router keeps its own rough map of what each GPU has seen. It doesn't need to look inside the GPUs. It just records every prompt it sends and where it sent it.
When a new request comes in, it asks one question: which GPU has the longest matching start of this prompt?
Then it sends the request there.
That one change takes the hit rate from 20% to 75% in SGLang's numbers. And because a cache hit means skipping most of the prompt processing, throughput nearly doubles.
How the router picks a GPU
It sends each request to the GPU that already has the longest part of the prompt cached, unless that GPU's queue is too long.
- RequestPrompt A plus a new turn
- RouterRemembers which prompts it sent where
Select a branch to follow its path.
The catch: you can't only chase the cache
If you route purely on cache matches, you get a new problem.
Popular prompts are popular. If one system prompt gets 40% of your traffic, a pure cache-matching router sends 40% of everything to one GPU while the others sit around. You have traded wasted compute for a traffic jam.
So real cache-aware routers balance two things. They prefer the GPU with the best match, but if that GPU's queue is much longer than the others, they give up on the cache and send the request to the least busy machine instead. It then builds its own copy of the cache, and the popular prompt now lives in two places.
Getting that trade-off right is most of the engineering. Too loyal to the cache and you get hot spots. Too eager to balance and you are back to round robin.
The same mechanism that hurt Anthropic
A few weeks ago I wrote about a routing bug at Anthropic. Their routing was sticky: once a user landed on a server, they kept landing there. When some servers were misconfigured, that stickiness meant the same users got hit again and again.
Cache-aware routing is stickiness on purpose. You want a conversation to keep going back to the same GPU, because that GPU remembers it.
Same mechanism, opposite result. Stickiness multiplies whatever is on the other end. If the server is healthy and has your cache, you get speed. If the server is broken, you get the bug every time.
Which is a good reason to pair sticky routing with per-backend health checks, and to be able to break the stickiness quickly when a backend goes bad.
What I built
I wrote a simulator in Go. No real GPUs, just workers with a limited prefix cache and a cost model: uncached tokens are slow, cached tokens are nearly free.
It generates realistic-ish traffic. A set of system prompts with uneven popularity, and multi-turn conversations where each turn extends the last.
Then it runs the same traffic through three routers:
- Round robin. Takes turns, ignores the cache.
- Least loaded. Sends each request to the shortest queue, also ignores the cache.
- Cache-aware. Picks the worker with the longest matching prefix, and falls back to the least loaded worker when that one's queue gets too long.
The numbers from a simulation show the shape of the effect, not production performance. The shape to look for is the one SGLang's team reported: hit rate is what moves throughput, and the load fallback is what keeps the busiest worker's queue from running away.
When it doesn't help
Cache-aware routing isn't free speed for everyone.
- If every prompt is unique, there is nothing to reuse. Routing can't create overlap that isn't there.
- If the cache is too small, popular prompts get evicted before the next request arrives.
- If you only have one GPU, there is no routing decision to make. The engine's own prefix cache already does the job.
The more your traffic repeats itself, the more this matters. Chat products, agents, and anything with a big shared system prompt sit right in the sweet spot.
The takeaway
For most services, a load balancer's job is to spread work evenly. For LLM inference, its job is to send work where it has already been done.
If you are running more than one GPU behind round robin, check your prefix cache hit rate. If it is low, the fastest upgrade available to you might not be hardware at all.
Sources
- Ying Sheng (xAI, LMSYS), "Efficient LLM Inference with SGLang", lecture slides: round robin 82,665 tokens/sec at 20% cache hit rate vs cache-aware 158,596 tokens/sec at 75%. These are the SGLang team's own reported numbers.
- PyTorch blog, "SGLang Joins PyTorch Ecosystem": xAI uses SGLang to serve Grok.
- SGLang documentation on RadixAttention and the cache-aware router.
- The simulator is my own and is not a benchmark of SGLang.
