Education › Inference › Stage 6: Distributed inference architecture

Disaggregated prefill and decode

Separate pools for each phase, KV transfer between them, and when the split pays off.

Advanced ~35 min read Module 11 of 15

Prefill is compute-bound and bursty; decode is memory-bound and steady. Running both on the same GPUs means they interfere: a long prompt arriving stalls every stream in the batch, and you cannot tune for time to first token and for streaming speed separately. Disaggregated serving puts them on different GPU pools and moves the KV cache between them. This lesson explains how it works, what the KV transfer costs, how to size the two pools, how vLLM, SGLang and Dynamo implement it, and the cases where it does not pay off.

After this module you can
  • Explain the interference problem that disaggregation solves
  • Trace a request through prefill pool, KV transfer and decode pool
  • Estimate KV transfer size and time for a link
  • Size prefill and decode pools from workload shape
  • Decide when aggregated serving with chunked prefill is the better choice

The interference problem

In an aggregated server, every scheduler step mixes decode tokens for running requests with prefill work for new ones. When an 8,000-token prompt arrives, its prefill takes a long, compute-heavy chunk of time, and every request in the batch waits for its next token. Chunked prefill softens this by slicing long prompts, but the two phases still share one GPU and one set of tuning knobs: batch sizes that favour decode throughput hurt TTFT, and vice versa.

Disaggregated serving separates them. A prefill pool of GPUs only runs prefills; a decode pool only runs decode. Each pool gets the batch sizes, parallelism and even GPU type that suit its phase. vLLM's documentation states the two benefits plainly: tune TTFT and inter-token latency separately, and control tail inter-token latency. It also states that disaggregation by itself does not improve throughput; the gain is in meeting both latency targets at once, which can improve goodput.

How a request flows

  1. A router or gateway receives the request and picks a prefill worker, ideally one that already caches the prompt's prefix.
  2. The prefill worker computes the KV cache for the prompt and the first output token.
  3. The KV cache is transferred to a chosen decode worker, over NVLink inside a node or RDMA between nodes, using a transfer library such as NIXL or Mooncake.
  4. The decode worker continues generation from that cache and streams tokens to the client.
  5. Both workers free or keep the cache according to their caching policy.
requestpromptKV via NIXL/RDMAstream tokensClientRouterprefix + load awarePrefill poolcompute-heavyDecode poolbandwidth-heavy
Disaggregated serving: a router sends the prompt to a prefill worker, the KV cache moves over a fast link to a decode worker, and the decode worker streams the answer.
SGLang: one prefill worker, one decode worker, and its router
bash
python -m sglang.launch_server --model-path "$MODEL_ID" \
  --disaggregation-mode prefill --port 30000 \
  --disaggregation-ib-device mlx5_roce0

python -m sglang.launch_server --model-path "$MODEL_ID" \
  --disaggregation-mode decode --port 30001 --base-gpu-id 1 \
  --disaggregation-ib-device mlx5_roce0

python -m sglang_router.launch_router --pd-disaggregation \
  --prefill http://127.0.0.1:30000 --decode http://127.0.0.1:30001 --port 8000

vLLM implements the same pattern through KV connectors set with --kv-transfer-config (NIXL, LMCache, Mooncake and others) and marks the feature experimental. NVIDIA Dynamo wraps vLLM, SGLang or TensorRT-LLM workers with --disaggregation-mode prefill|decode and adds KV-aware routing and automatic pool scaling, as covered in the open-source track.

The cost: moving the KV cache

Transfer size and time (illustrative model, 128 KiB of KV per token)
text
4,000-token prompt x 128 KiB/token = 500 MiB to move per request

at ~50 GB/s (fast RDMA or NVLink path) -> ~10 ms
at ~1.25 GB/s (10 Gb Ethernet)        -> ~420 ms

The transfer adds directly to time to first token unless it overlaps with computation (engines stream layers as they finish). On a fast fabric it is a small price for removing interference; on ordinary Ethernet it can cost more than the prefill itself. Disaggregation therefore assumes high-bandwidth, RDMA-capable links between pools, and it favours models with compact caches (grouped-query attention, FP8 cache).

Watch out

If your prompts are short, your decode batches small, or your network slow, disaggregation mostly adds complexity and transfer latency. Aggregated serving with chunked prefill and KV-aware routing is often the better answer. Measure both before committing.

Sizing the two pools

Deployments are often described as xPyD: x prefill workers, y decode workers. The right ratio comes from the workload. Prefill load scales with input tokens per second; decode load scales with concurrent sequences and output tokens per second. A RAG service with long prompts and short answers needs relatively more prefill capacity; a writing assistant with short prompts and long answers needs more decode capacity.

  • Measure one prefill worker's input-token throughput at your TTFT target, and one decode worker's sequence capacity at your ITL target.
  • Divide expected peak input tokens per second by the first, and peak concurrent sequences by the second, to get starting values for x and y.
  • Let an autoscaler adjust each pool independently; that independence is one of the main operational gains. Dynamo's Planner does exactly this against TTFT and ITL targets.
  • Watch both pools' queues: a growing prefill queue raises TTFT; a full decode pool blocks KV handoffs.
Hands-on practice

Aggregated versus disaggregated on two GPUs

  1. On a two-GPU machine (NVLink if possible), run one aggregated engine on GPU 0 and benchmark a mix of 6,000-token and 200-token prompts at moderate concurrency; record TTFT and p99 ITL.
  2. Launch the SGLang prefill and decode workers and router from this lesson (or the Dynamo vLLM disaggregated example) using one GPU each.
  3. Run the identical benchmark against the router and record the same metrics.
  4. Compute the KV transfer size for your average prompt with the KV-cache formula and estimate transfer time on your link.
  5. Compare p99 ITL between the two setups; explain any change in TTFT using the transfer estimate.
  6. Write a recommendation: which setup, for which workload, and what you would test at larger scale.
Cheat sheet

Disaggregated prefill and decode — at a glance

Main things to focus on

  • Prefill and decode interfere when they share GPUs; disaggregation separates them.
  • Gain: tune TTFT and ITL independently and control ITL tails, not raw throughput.
  • Cost: moving each request's KV cache between pools.
  • Needs fast RDMA or NVLink links and benefits from compact caches.
  • Size xPyD from input-token load (prefill) and concurrency (decode).
  • Short prompts or slow networks: stay aggregated with chunked prefill.

Formulas

KV transfer = prompt_tokens x KV_bytes_per_tokenBytes moved per request
t_transfer ~ bytes / link_bandwidthAdded to TTFT unless overlapped
x ~ peak input tok/s / prefill worker capacityPrefill workers
y ~ peak concurrent seqs / decode worker capacityDecode workers

Engine flags

sglang.launch_server ... --disaggregation-mode prefill|decodeSGLang worker role
sglang_router.launch_router --pd-disaggregationSGLang PD router
vllm ... --kv-transfer-config '{"kv_connector":"NixlConnector",...}'vLLM KV connector (experimental)
python3 -m dynamo.vllm --disaggregation-mode prefill|decodeDynamo worker role

Transfer libraries

NIXLNVIDIA's transfer library over NVLink, RDMA, storage
MooncakeKV transfer and cache store used by several engines
LMCacheKV cache layer with offload and sharing
--disaggregation-ib-device DEVSGLang: RDMA device used for KV transfer

When to use

long prompts + strict ITL SLO + fast fabricDisaggregate
short prompts or slow networkStay aggregated
prefix-heavy trafficAdd KV-aware routing either way

Common pitfalls

  • Disaggregating over ordinary Ethernet and making TTFT worse.
  • Expecting a throughput gain rather than better latency control.
  • Fixed prefill/decode ratios that ignore how the workload shifts during the day.
  • Ignoring the decode pool's capacity, so KV handoffs queue.
  • Skipping the aggregated baseline benchmark.
Quiz

Check your understanding

5 questions · 4 to pass · answers are explained as you go. Your best score is saved on this device only.

Progress and quiz scores are saved in this browser only. Back up or restore on the hub.

Was this lesson useful? Tell me what to improve →