20.11 Serving layouts: one process, replicas, and distributed pools
Serving architecture decides where weights and request state live and which components communicate on every token. Start with a single process and add distribution when memory, load, latency, or recovery requirements justify it. The right layout follows the workload and model, rather than the provider’s product names.
Concepts from other sections (10)
This section uses these ideas. Each has a short definition and a link to the section that explains it in full. Tap a dotted term in the text to preview it.
- Prefill/decode disaggregation: running prompt prefill and token decode on separate engines, so the two phases stop competing for one batch. Read more: 23.7 Disaggregated prefill and decode
- logits: unnormalized log-scores that softmax turns into probabilities; here the table stores . Read more: 6.1 Byte bigram: counts, logits, safetensors v0
- bounded admission: a fixed-capacity command queue filled with
try_send, so a full queue is an immediate 429. Read more: 23.6 tl-serve: OpenAI-compatible HTTP + SSE on tokio/hyper - Mixture of experts (MoE): a layer of many expert MLPs of which a router picks per token. Read more: 13.8 Mixture of Experts
- Idempotency: the property that re-running a step does not change its result, which makes pipelines recoverable. Read more: Chapter 1: Foundations in Data Engineering
- cached block: a block with no running request on it that is still findable by hash or in the radix tree, and can be evicted. Read more: 23.5 Block manager with prefix cache (none, hash, radix)
- Graph capture: recording a device execution graph for later replay with supported shapes and buffers. Read more: 20.10 Runtime controls and inference flags
- lead time: the delay from an autoscaling decision to a replica serving traffic, including node provisioning and cold start. Read more: 20.7.5 Adapter fleets and operations
- failure domain: the set of replicas lost together in one failure (a node, a zone, a cluster); the fleet is sized so the replicas outside the largest one still meet peak load. Read more: 20.7.5 Adapter fleets and operations
- TTFT (time to first token): time from a request’s arrival to its first generated token. Read more: 23.4 Chunked prefill (mixed prefill + decode batches)
Learning objectives
- Compare in-process inference, a local server, replicas, and model-parallel serving.
- Account for state transfer in prefill/decode disaggregation.
- Include admission, routing, and failure handling in capacity design.
Layouts and their state boundaries
Section titled “Layouts and their state boundaries”| Layout | Where state lives | When it helps | Cost or failure boundary |
|---|---|---|---|
| In-process model | Application process owns weights and caches | Debugging logits, custom training/evaluation, low-concurrency use | App and model share memory and lifecycle |
| Local HTTP engine | One service process or engine group owns weights and active KV | Shared API, streaming, concurrent callers | Serialization, bounded admission, process restart loses active state |
| Independent replicas | Every replica has a complete model or model-parallel group | More aggregate capacity and failover | Duplicated weights; routing affects prefix-cache locality |
| Tensor parallel | Weight matrices and partial activations span devices | Model/layers do not fit or large-batch work benefits | Frequent collective latency and interconnect pressure |
| Pipeline parallel | Layer ranges on different devices | Distribute large weights with fewer cross-stage tensor exchanges | Pipeline scheduling, bubbles, and request concurrency |
| Expert parallel | Experts across devices | Fit and execute MoE weights | Token dispatch, expert imbalance, and all-to-all traffic |
| Prefill/decode pools | Prompt processing and token generation on different workers | Independently size phases with different bottlenecks | Transfer KV, manage ownership, and preserve request/sampling state |
| Offline batch queue | Jobs and results are durable outside the engine | Throughput-first workloads with relaxed latency | Queue delay and retry/idempotency semantics |
A “replica” may use eight GPUs internally. Eight replicas and TP=8 describe very different memory, request routing, and failure behavior. Quantify both independent replica count and devices per replica.
Disaggregation must move real state
Section titled “Disaggregation must move real state”The prefill worker reads the prompt and creates attention state. The decode worker needs the compatible KV blocks, positions, model/adapter revision, request history, and sampler state. If the first output token was already sampled, specify whether it is transferred or sampled by the receiver. Duplicate sampling changes the RNG stream and can duplicate output.
For an illustrative 2 GiB transfer over an effective 50 GB/s path, the byte-only lower bound is about 43 ms. Allocation, packing, queueing, network contention, synchronization, and any retransmission add to it. If the saved prefill/decode interference is smaller, separating the phases can make latency worse. Reusing compatible cached blocks can reduce transfer, but adds cache identity and ownership logic.
This is the tradeoff studied by DistServe. It is a workload-dependent design, not an automatic improvement over colocated execution. The worked disaggregated engine shows block transfer and cleanup; the capacity parts compare bandwidth and synchronization costs.
Routing and admission are part of performance
Section titled “Routing and admission are part of performance”Route by enough state to avoid hot spots: queued/running work, prompt/output lengths, available cache blocks, compatible prefix residency, and model/adapter identity where the engine exposes them. Pure request-count balancing treats a 100-token request like a 100,000-token one. Prefix-aware routing can reduce prefill but overload a popular replica. Compare load and locality together.
Bound admission and queue depth. Overload should produce a defined response or deadline outcome rather than unbounded waiting. Propagate cancellations so abandoned requests release KV. Define whether retries restart generation; a process failure normally loses ephemeral KV unless the system explicitly replicates or exports it. Retrying a partially streamed request cannot silently promise the original byte stream.
Recovery and scale-out
Section titled “Recovery and scale-out”Warm replicas avoid model download, device allocation, compilation, and graph capture delay. Scale on queueing and sustainable goodput with measured startup lead time. GPU utilization alone cannot distinguish a healthy saturated service from one violating every latency target. Include spare capacity for the failure domain the service must survive, such as one worker group or one node.
The Kubernetes deployment reading connects replicas to pods and failure domains. The model release chapter; record artifact compatibility before routing traffic between revisions.
Key terms
Section titled “Key terms”- Replica: an independently schedulable copy of the serving model, possibly spread across devices.
- Disaggregation: placing distinct phases or responsibilities in separate worker pools.
- State ownership: the rule identifying which worker may mutate or release a request’s cache and sampling state.
Summary
Section titled “Summary”Count device groups, state transfers, and restart boundaries. Distribution improves a service only when its added communication and coordination fit the workload’s latency and cost budget.
Review questions
Section titled “Review questions”-
Why can prefix-aware routing improve TTFT and worsen tail latency at the same time?
Answer
It can avoid repeated prefill while concentrating popular prefixes on a busy replica, increasing queueing. -
What must a KV handoff preserve beyond tensor bytes?
Answer
Model and adapter identity, positions, block ownership, committed token history, sampler/RNG state, and the first-token convention.