Book a 30-min callBook a call

How LLM inference serving works: prefill, decode, continuous batching and throughput

How LLM serving works: prefill and decode, TTFT and inter-token latency, continuous batching, chunked prefill, disaggregation and speculative decoding.

Request bars of different lengths queued beside a GPU box with four filled slots, and a dashed loop arrow carrying a freed slot back to the queue.
Written by
BYD Tech
Published
Topic
Deep dives
Reading time
16 min read

Questions people ask

Why does the first token take longer than the rest?

The first token waits for prefill, a full pass over the whole prompt, plus any time the request spent queued. Later tokens each need only one decoding step. Long prompts, busy servers and prefill work that has to wait behind other requests all raise time to first token; prefix caching and chunked prefill are the usual remedies.

Does continuous batching change the model's outputs?

It is not meant to. Each sequence attends only to its own tokens, so which other sequences share a step should not change the result. In practice, different batch sizes can select different GPU kernels and change floating-point rounding slightly, which can flip a token in rare close cases, even with greedy decoding. If you need bit-for-bit repeatability, check what your server guarantees.

Is goodput the same as throughput?

No. Throughput counts all the tokens or requests a server completes per second. Goodput counts only the requests that met their latency targets, such as a p99 TTFT and TPOT, so it falls when a server is pushed past the point where it can keep its promises to users, even while raw throughput still rises.

When does speculative decoding not help?

When the server is already running large batches and is compute-bound, verifying draft tokens that get rejected wastes work, so the gain shrinks or turns negative. It also helps little when the drafter rarely guesses right, for example on creative text with high sampling temperature. It helps most for single streams or light load, and for tasks that repeat their input, such as code edits and extraction.

Should I quantize before adding GPUs?

Often it is the cheaper first step, because decode is limited by memory traffic and a smaller model reads fewer bytes per token and leaves more room for KV cache. Measure accuracy on your own evaluation set first. If quality holds, quantization may let a model fit on fewer GPUs; if it does not, tensor parallelism across more GPUs keeps full precision.

Building something like this?