Prefill, decoding, and phase disaggregation
Model first-token and streaming latency before separating prompt processing and token generation across workers.
On this page
The question for today
What you’ll understand
- Distinguish prefill computation from incremental autoregressive decoding.
- Calculate KV transfer costs and serial latency components.
- Evaluate disaggregation using useful throughput under both first-token and streaming objectives.
A long prompt and a stream of newly generated tokens place different demands on an inference worker. Prefill processes the supplied prefix, while decoding repeatedly advances active sequences. Sharing a worker can improve utilization, but a large prefill batch can interfere with streaming deadlines. Separating phases creates scheduling freedom and a new state-transfer dependency. Whether that trade improves a system depends on request lengths, concurrency, hardware, network bandwidth, and the latency objectives that matter to users.
Two phases, several latency clocks
During prefill, a causal Transformer processes known prompt positions with considerable parallelism and constructs the cache. During decoding, each sequence's next token depends on its preceding token choice, although many sequences can be batched together. Prefill is often more compute intensive and decoding more sensitive to memory movement at modest batch sizes. These descriptions are tendencies, not universal hardware laws: context length, model shape, attention kernels, and batching can change which resource limits either phase.
Measure time to first token from a declared boundary, such as request receipt. It can include queueing, tokenization, prefill, transfers, and the first decode operation. Streaming latency concerns subsequent intervals; averages can hide pauses, so report an appropriate percentile and define whether it is per request or per token. End-to-end completion includes output length. A system can meet a first-token target while delivering the rest of an answer too slowly, or improve streaming after making users wait longer initially.
Disaggregation exchanges interference for communication
A disaggregated design assigns prompt processing and ongoing decoding to different worker pools. Each pool can use a suitable batch policy, parallelism arrangement, and potentially hardware type. The prefill worker must convey compatible cache state and request metadata to the decoder. DistServe and Splitwise investigate this phase separation with explicit attention to resource allocation and transfer. Their measured improvements belong to their evaluated workloads and configurations; they are not a guarantee for every cluster or service.
Estimate transfer using bytes divided by effective payload bandwidth, then add serialization, coordination, and network queueing. A link's advertised line rate is not the application's sustained transfer rate. Tensor parallelism may place cache shards on several devices, and data movement can contend with model execution or other collectives. Transfer overlap helps only to the extent that dependencies permit it. For a short prompt on an already busy network, a colocated worker can easily be the better design.
Optimize goodput under the workload distribution
Goodput counts useful completed work that satisfies declared service objectives, rather than every generated token. Specify both first-token and streaming thresholds and report the fraction of requests satisfying them. Aggressive batching can increase throughput while making interactive requests miss deadlines. Compare designs at matched hardware cost or power budgets and include the cost of spare capacity, transfers, and rejected or cancelled work in the result.
Replay joint prompt/output length distributions, including bursts. Size the pools so one phase does not simply push a persistent queue onto the other. Consider overload, a lost decoder, a failed transfer, and cancellation while cache state is in flight. Bound queued work and assign deadlines across both pools. Begin with traces from a colocated baseline; phase separation should solve a measured interference or provisioning problem rather than add a network boundary without evidence.
Work it through
Price a cache handoff in milliseconds
A prompt leaves 512 MiB of cache. Effective transfer bandwidth is 16 GiB/s. Both designs have the same 8 ms preparation overhead. Prefill takes 80 ms, queueing 20 ms, and first decode 12 ms. Assume serial stages.
Convert 512 MiB to 0.5 GiB. Payload transfer requires at least 0.5/16 = 0.03125 seconds, or 31.25 ms.
Add the stated stages: 20 + 8 + 80 + 31.25 + 12 = 151.25 ms to first token. This excludes any additional transfer setup not already included in the 8 ms.
Suppose disaggregation removes 60 ms of prefill/decode interference but introduces this 31.25 ms handoff and 10 ms of extra queueing. Net saved latency is 60 − 31.25 − 10 = 18.75 ms under these simplified measurements.
The example can benefit from separation, but the 18.75 ms margin is workload specific. At half the transfer bandwidth, the same assumed benefit would disappear.
The living notebook
Explore the model
Interactive lab · queue
Capacity must leave room to drain
Adjust arrival and service rates in max(0, 4 + (λ−μ)t), a constant-rate fluid backlog. A separate M/M/1 residence readout assumes Poisson arrivals, exponential service, one server, and λ<μ. Neither model represents token batching, two worker pools, or real KV transfers.
- Fluid backlog
- 4
- Net rate · λ − μ
- −1 /s
- M/M/1 mean residence
- 1 s
Fluid backlog starts at 4 and follows max(0, 4 + (λ − μ)t). The separate M/M/1 residence-time formula assumes Poisson arrivals, exponential service and λ < μ. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.
Look forSeparating phases does not remove queueing; each stage needs capacity relative to the work offered to it.
Pause & reason
Check your understanding
Your turn
Try it yourself
A 1 GiB cache handoff uses effective bandwidth 8 GiB/s plus 5 ms fixed overhead. Separation saves 100 ms of interference and adds no queueing. Estimate its latency effect under a serial model.
Take a moment to make a prediction or work it out on paper. Open a hint when you need one.
Give me a hint
Convert bytes divided by bandwidth into seconds before adding milliseconds.
Compare with the solution
Payload transfer takes 1/8 second, or 125 ms. With overhead, the added cost is 130 ms. Saving 100 ms therefore makes the request 30 ms slower under the stated serial model. Overlap or different pool utilization could change the result, but neither has been assumed here.
Keep the idea
Take it with you
- Define first-token, streaming, and completion clocks explicitly.
- Disaggregation trades scheduling interference for state transfer and extra queue boundaries.
- Compare deadline-satisfying work under realistic lengths and matched resource budgets.
Read further
Original sources and deeper explanations to follow at your own pace.
Optional progress, saved in this browser when available. Revisit any lesson at any time.
Lesson not marked complete.