A GPU writing text for 32 people is barely slower per word than one writing for a single person. The catch is each person's conversation history, and it sets how many people one card can really serve.
Engineer's view. This is the N+1 query fix. One query with many IDs pays the round trip once, and each extra ID adds only its own rows. A decode step reads the model's weights once for every user. Each user adds only their own cache. Once the caches outweigh the weights, every extra user slows everyone down.
TL;DR. Continuous batching lets one GPU serve many users because the model's weights are read once per step for all of them. The limit is each user's stored conversation, so longer conversations mean fewer users per card.
Explain Like I'm 5
A teacher reads one page of a big rulebook out loud, then every kid at the table writes one more word of their own story. Then she reads the page again, and they each write one more word.
Reading the rulebook takes the same time for one kid or thirty. But before each word, every kid also rereads their own story so far. Short stories are quick to reread. Long ones slow the whole table down.
When a kid finishes, a new kid sits down right away. Nobody waits for the slowest writer to finish first.
The Problem
You have shipped this bug before, and it had nothing to do with AI.
You had 10,000 jobs to process. You grouped them in fifties and ran each group with Promise.all. Most jobs took 50 milliseconds. A few took five seconds. Every group waited for its slowest job, so 49 workers sat idle while one finished. The fix was a worker pool. When a worker finishes, it takes the next job at once.
Then you capacity-planned the new service. You timed one request, divided the second by it, and wrote down a throughput. It was wrong in both directions. At low load the box was far faster than your sum. Under real load it fell over sooner than predicted, because some requests were much heavier than the one you timed.
A model server has both bugs at once. Text comes out one token at a time, and each user's answer has a different length. Group requests into a fixed batch and the batch runs until its longest answer ends. In our simulation of realistic answer lengths, the slots sat busy only 21% of the time.
Capacity planning breaks too. Timing one user tells you almost nothing about 32 users, and the answer depends on how long their conversations are.
The fix: refill each slot the moment its answer ends, and size the batch by how much conversation history each user carries, not by a request count.
Read the full post on The AI Commit
How Continuous Batching Lets One GPU Serve Many Users at Once carries the rest: the fix and why it works, the code to change for each role, how to tell it worked, when it is the wrong tool, and an interactive model you can play with.
Originally published at theaicommit.com, a daily AI engineering lab for software engineers. The original has an interactive version you can play with, and the full runnable code is on GitHub.
Top comments (0)