Chapter 23
Parallel, Replicated, and Disaggregated Serving
On this page
A serving fleet places model parameters, KV state, and request phases across failure domains. Parallelism is useful only when its memory or throughput gain exceeds communication, synchronization, and scheduling cost at the target shapes.
One replica is no longer enough: a model may not fit one device, traffic exceeds one accelerator, and phases interfere. This section places weights, KV, and phases across devices and pools. Two communication facts drive everything below. A collective is a synchronized exchange, such as an all-reduce, whose time is roughly a fixed latency per step plus bytes divided by link bandwidth, and it completes at the pace of the slowest participant. Decode sends small messages every few milliseconds, so the latency term and the slowest peer dominate exactly where training-style large-message efficiency does not apply.
Replicas and model-parallel groups¶
Data-parallel serving replicas hold equivalent model state and process different requests. They scale aggregate capacity and isolate failures but do not make one request faster unless the request can be divided at a higher level.
Tensor parallelism shards large layer operations across devices and introduces collectives in each layer. It reduces parameters per device and can lower single-request compute time, but small decode messages may underutilize links and every step waits for the slowest peer.
Pipeline parallelism assigns layer ranges to stages. It reduces per-device weights and can overlap microbatches, but latency includes stage traversal and bubbles depend on the number and uniformity of microbatches. Dynamic continuous batches complicate stable pipeline schedules.
Expert parallelism places mixture-of-experts experts across devices. It reduces resident expert weights per device and increases aggregate capacity, but token routing creates all-to-all traffic and load imbalance. Hot experts and small per-expert token counts can dominate decode.
Context parallelism must be phase-specific. Prefill context parallelism (PCP) partitions prompt query positions and, depending on the algorithm, exchanges or circulates their K/V context. It is chiefly a long-prompt TTFT and attention-working-set tool. Decode context parallelism (DCP) sequence-shards the historical KV cache and merges partial attention for each new token. It is chiefly a cache-capacity and decode-goodput tool. PCP adds a rank dimension in vLLM; DCP reuses allocated ranks rather than multiplying their count. Without PCP those ranks lie inside TP, while newer combined layouts can span PCP as well. Part V gives the version-specific constraints. Neither PCP nor DCP means choosing a different TP degree for the two serving phases.
Part V develops these mechanisms in depth. For serving, the decision is driven by request latency, active batch, KV placement, link topology, and the model's fit, not training precedent.
Choosing the smallest group¶
Use the smallest model-parallel group that fits weights, KV reserve, runtime workspaces, and failure headroom while meeting latency. Increasing tensor-parallel degree can reduce local compute but adds communication and consumes more devices per replica, reducing the number of independent batches the fleet can run.
A useful comparison includes:
- per-device weight and KV bytes;
- prefill and decode latency curves by batch and context;
- collective time and exposed synchronization;
- replica count and queueing under the arrival process;
- fault blast radius and repair time;
- cost per good request or output token.
The fastest isolated request configuration may have worse fleet goodput because it creates fewer replicas and longer queues.
The running service's 14 GB model fits comfortably on one 80 GB device, so tensor parallelism is a choice, not a necessity. Splitting across two devices moves the weight-streaming floor from 4.7 ms toward 2.4 ms but inserts collectives into all 32 layers of every step and consumes two devices per replica. Compare two independent replicas against one two-way group at the same offered load and hardware budget. Replication avoids the new collectives and preserves independent scheduling, while tensor parallelism can help requests that otherwise miss their latency limits; the goodput winner requires measurement.
Topology-aware placement¶
Map communication-heavy peers onto the fastest available links and keep the mapping stable enough for engine artifacts and cache locality. Know which links share bandwidth, which paths cross sockets or switches, and whether collectives contend with KV transfer or storage traffic.
Topology faults are performance faults before they become hard errors. A degraded link or throttled peer slows every synchronized device. Record per-rank timing and collective skew; aggregate GPU utilization can hide one straggler holding the group.
Heterogeneous accelerators require separate performance models and engine variants. Route shapes to the hardware that meets their phase objective, but include transfer, queue, and fragmentation costs. A nominally faster device can lose if its pool is saturated or lacks the required adapter/precision path.
Prefill-decode disaggregation¶
Colocated workers run both phases and retain KV locally. This is simple and avoids a phase-boundary transfer, but long compute-heavy prefills can interfere with cadence-sensitive decode and both phases must share one parallelism and capacity plan.
Disaggregation assigns prefill and decode to different worker pools. It allows phase-specific hardware, batch, parallelism, and scaling, and it isolates interference. The handoff is KV state plus request metadata.
Prefill and decode pools specialize independently; the price is a KV handoff whose bytes, protocol, and queueing must be modeled before committing to the architecture.
For transferred KV bytes X and sustainable path bandwidth BW, a lower bound is:
t_handoff >= X / BW + fixed transfer overhead
The actual path includes source readiness, registration, serialization or layout conversion, network queueing, destination placement, and synchronization. Long prompts create more state to transfer but also more prefill work that specialization may save.
For the running service, a 2,000-token prompt hands off about 260 MB of KV (2000 * 131 kB). Over the assumed 50 GB/s path that is roughly 5 ms plus protocol overhead. The transfer lets the decode pool consume the prefill result while specializing independently; compared with colocated serving, it does not remove an otherwise duplicated prefill. A contended or slower path can erase the specialization and interference benefit, which is why the bound is a starting point and not a verdict.
Different TP sizes for prefill and decode¶
“Prefill TP” and “decode TP” usually refer to the same tensor-parallel mechanism configured independently in two worker pools, not two new forms of tensor parallelism. For example, one prefill instance could use TP=4 while each decode instance uses TP=2. Each engine still has its own weight shards, collectives, and KV ownership. The request crosses between engines; changing phase does not automatically resize a live TP group.
vLLM's disaggregated-prefilling documentation describes choosing parallel strategies independently for TTFT and inter-token latency. DistServe at OSDI 2024 is an earlier example that co-optimized phase-specific resources and parallelism. Runtime support still depends on the connector and model layout used for the handoff.
Why might the degrees differ? Large prefill matrix operations can amortize communication, and a tight first-token budget can justify a wider group. Small-batch decode performs frequent short steps; collective latency and local matrix shape can make a narrower group more efficient. But there is no rule that prefill TP must be larger. Weight fit, long-context KV reads, aggregate memory bandwidth, batch size, and a strict token-gap target may favor wider decode. Measure both phases rather than deriving the answer from “compute-bound” and “memory-bound” labels alone.
Consider an illustrative head-sharded layout for the running service's eight KV heads, with no PCP or DCP. Keep all layers on each group and use equal head partitions:
| Prefill rank, TP=4 | KV heads produced | Destination, TP=2 |
|---|---|---|
| P0 | 0-1 | D0, which owns heads 0-3 |
| P1 | 2-3 | D0, which owns heads 0-3 |
| P2 | 4-5 | D1, which owns heads 4-7 |
| P3 | 6-7 | D1, which owns heads 4-7 |
The logical cache is unchanged; its physical ownership changes. For a 2,000-token prompt, the exact FP16 KV size is 250 MiB (2000 * 128 KiB). Each source owns 62.5 MiB and each destination must reserve 125 MiB, excluding block padding and workspace. A connector must map head ranges and token blocks into the destination layout, not copy P0's buffer to D0 and assume the other heads are present. This arithmetic describes ownership, not a measured speedup or a recommended TP setting.
Different TP sizes are often called heterogeneous TP in connector documentation. Support is model- and layout-specific: the NixlConnector compatibility matrix distinguishes dense head-sharded attention, replicated MLA state, and hybrid recurrent models. Check the exact runtime, connector, KV dtype, attention backend, and model restrictions. A valid pair of TP sizes is not proof of a supported handoff.
Pool size is a separate decision. One TP=4 prefill instance plus two TP=2 decode instances uses eight GPUs; it does not create one TP=8 replica. Compare this layout with four colocated TP=2 instances under the same traffic and GPU budget. Include queueing, KV reshaping/transfer, destination capacity, TTFT, token-gap tails, and cost per SLO-compliant request. Disaggregation provides tuning freedom, not a guaranteed raw-throughput improvement.
Handoff protocol¶
Reserve destination capacity, transfer state, validate its contract, and publish ownership before decoding. Source release follows the protocol's acknowledgement and recovery rules; failed attempts must be idempotent.
A correct handoff identifies model/adapter version, token range, position state, KV dtype and layout, source blocks, destination allocation, and ownership. One safe sequence is:
- destination admission reserves capacity;
- source finishes and marks transferable committed blocks;
- data moves with checksums or transport integrity;
- destination confirms visibility and compatible metadata;
- ownership transfers or source references are released;
- decode becomes schedulable.
Retries need idempotent request and transfer identifiers. If the destination fails after receiving some blocks, cleanup must not free source state prematurely or leak destination allocations. Avoid a protocol that can generate the first token twice after a retry.
Routing with state affinity¶
Routing decisions occur at several levels:
- gateway to model/version pool;
- request to replica or prefill group;
- prefill result to decode group;
- resumed session to existing or migrated KV;
- expert or adapter work within a group.
Least-loaded routing is insufficient when state has locality. Estimate completion time including queue, cache hit, adapter load, transfer, and phase cost. Use bounded stickiness: prefer the state owner while its delay advantage remains positive, then migrate or recompute rather than creating an unbounded hot spot.
Independent scaling and backpressure¶
In a disaggregated system, prefill and decode capacity must balance in units that reflect the workload. Request rate alone is misleading; prefill load follows uncached input tokens and encoder work, while decode load follows generated tokens and retained contexts.
If prefill outruns decode, completed KV accumulates and consumes transfer buffers or destination memory. If decode outruns prefill, expensive decode devices idle. Add bounded inter-stage queues, destination reservations before prefill commitment, and autoscaling signals based on predicted phase work and SLO risk.
Fault domains and recovery¶
A model-parallel group generally fails as a unit when one peer disappears. Drain new admissions, fail or retry affected requests according to commit state, and replace the group. Replicas provide capacity redundancy; model-parallel ranks do not.
Replaying a prefill can reconstruct KV if the input and model version are available, but it increases first-token latency and may violate deletion or privacy policy. Replicating KV improves recovery but doubles state traffic and memory. Choose by SLO, prompt cost, and failure frequency.
For streaming responses, retries after emitted tokens are delicate. The service can resume only if it can reproduce exact state and avoid duplicate bytes, otherwise it should terminate with a clear partial-response error. Exactly-once token streaming across arbitrary failures is an application protocol, not an automatic property of the model engine.
Design Exercises¶
- Why can increasing tensor-parallel degree reduce fleet goodput?
- How would you choose between replication, tensor parallelism, and pipeline parallelism for serving?
- Derive the break-even terms for prefill-decode disaggregation.
- Design a correct and retry-safe KV handoff protocol.
- How should routing balance queue delay against state locality?
- What changes in autoscaling and failure handling after disaggregation?
Worked Solutions¶
1. Tensor-parallel degree¶
More shards reduce weights and compute per device but add per-layer collective latency and synchronize on the slowest peer. Small decode messages may use links poorly. A larger group consumes more GPUs per replica, so the fleet runs fewer independent batches and may queue longer. Compare SLO-constrained request goodput for the whole fleet, including collective skew and failure blast radius, rather than single-request kernel speed.
2. Parallelism choice¶
Start with the smallest group that fits weights, KV reserve, runtime workspace, and safety margin. Prefer replicas for aggregate independent traffic. Add tensor parallelism when the model does not fit or its reduced local compute offsets collectives at target batch. Consider pipeline parallelism when layer partitioning fits the topology and enough compatible microbatches exist to control bubbles. Model queueing, replica count, context, prefill/decode separately, and topology rather than copying the training layout.
3. Disaggregation break-even¶
Benefits are phase-specific batching and hardware, independent scaling, better parallelism choices, and removal of prefill-decode interference. Costs are KV transfer bytes over sustainable bandwidth, fixed handoff and synchronization, extra queueing, destination reservation, network contention, layout conversion, and operational failure modes. Evaluate goodput under both first-token and token-cadence SLOs across the joint prompt/output distribution. The design wins only when the benefit exceeds all handoff terms at fleet scale.
4. KV handoff¶
Give the transfer an idempotent identity and reserve compatible destination blocks first. The source transfers only committed state with model, adapter, token range, position, dtype, and layout metadata. Verify integrity and visibility before making decode schedulable, then atomically transfer ownership or release source references. Retries discover completed chunks, and failures clean up destination partials without destroying the source's recoverable copy. Token commit and client streaming have separate idempotency rules.
5. Locality-aware routing¶
Predict time to useful progress on each eligible destination: queue plus missing prefill or transfer plus execution, adjusted for SLO, tenant, health, and memory pressure. Prefer a cache or adapter owner only while its saved work exceeds extra queue delay. Replicate very hot immutable state, use bounded stickiness for sessions, and retain a recompute fallback. Validate the predictor against actual completion time and prevent one popular prefix from hot-spotting a replica.
6. Scaling and failure¶
Scale prefill from uncached input/encoder work and first-token risk; scale decode from generated-token demand, context distribution, KV occupancy, and cadence risk. Balance the bounded handoff queue and reserve destination memory before producing more state. Failure recovery now spans two pools and a transfer protocol: retry idempotently, reconstruct or replicate KV by policy, avoid duplicate streamed tokens, and keep capacity reserve for loss of a group or network path.