All glossary terms

Serving

Continuous batching

A scheduling style that admits a new request the moment an old one finishes. It keeps decode slots busy and raises how many tokens a GPU returns per second.

Early serving stacks filled a fixed batch of requests, ran them to the end, and only then started the next batch. That was fine for image generation, where every request does similar work. Text requests are nothing like that: one user asks for a two-line summary and another pastes a document and asks for an essay. A batch that started together must wait for its slowest member, so the slot holding the short reply sits idle while a long generation crawls along.

Continuous batching fixes the unit of scheduling. Instead of "start a batch", each decode slot is refilled the instant it empties, inside the forward pass. New requests join mid-batch, finished requests leave mid-batch, and the GPU keeps its whole batch dimension busy nearly all the time.

The cost is a more complex scheduler: the server has to copy new requests in and out of the running state, manage memory so late joiners and the KV cache coexist, and decide what to do when it runs out of room. That is the practical interview territory, because the two failure directions are opposite: admit too eagerly and everyone suffers through preemptions and re-queues, admit too slowly and the GPU idles while demand queues up.

It is useful to name what it does to the two metrics you care about. Aggregate tokens per second rises a lot, because every slot is busy. But per-user tokens per second can fall slightly under load, since more users share the same bandwidth. The honest framing: continuous batching trades a small latency tax per user for a large throughput gain per GPU.

A worked example

A server with 8 decode slots, 40 tokens per second per slot, responses averaging 500 tokens, watched over a 25 second window in which the longest request needs all of it.

  1. Capacity in the window: 8 slots x 25 s x 40 tokens/s = 8,000 generated tokens.
  2. Static batching runs one group of 8 to the end: 8 responses, and any slot whose request finished early does nothing for the remainder.
  3. Continuous batching keeps every slot generating for the full window: 8,000 tokens of output.
  4. At 500 tokens per response, 8,000 tokens of output is 8,000 / 500 = 16 completed responses instead of 8.

Same GPU, same 25 seconds, roughly twice the completed requests, because no slot idles waiting for a straggling response to finish.

Where this shows up

Test yourself

Related terms