Disaggregated Serving, Prefix Caching & Distributed Inference
When scaling LLMs to thousands of concurrent users, traditional monolithic serving engines hit a fundamental wall: the structural conflict between Prefill and Decode.
Prefill is compute-bound, processing thousands of input tokens in parallel with high operational intensity. Decode is memory-bandwidth bound, generating one token at a time with near-zero operational intensity. When both run on the same GPU, long prefills cause severe head-of-line blocking, inducing massive Inter-Token Latency (ITL) jitter for active users.
In this chapter, we engineer the modern distributed serving architectures that solve this bottleneck: Prefill-Decode (PD) Disaggregation, Radix Tree Prefix Caching, and Topology-Aware Model Parallelism (Tensor, Pipeline, and Expert Parallelism for frontier MoE architectures).
Imagine a high-end coffee shop that only has one worker. One customer orders 50 catered drinks for an office meeting (a giant prompt / prefill), while five other customers are standing in line waiting for a single sip of espresso (token decoding). If the barista stops to brew all 50 catered drinks, the five espresso drinkers wait 20 minutes for their next sip.
Disaggregated Serving separates the shop into two specialized stations: a high-capacity brewing station dedicated solely to large catering orders (Prefill nodes), and rapid-fire espresso machines dedicated solely to pouring one cup at a time (Decode nodes). The brewing station makes the coffee concentrate (KV cache) and pipes it across the counter (over high-speed NVLink/RDMA) to the espresso team.
Prefix Caching is having pre-brewed signature blends ready to pour: if 100 customers order the exact same specialty cold brew (shared system prompt or documents), the barista skips brewing entirely and serves it instantly.
1. The Prefill-Decode Interference Problem
In traditional monolithic serving (e.g., standard vLLM or Hugging Face TGI), incoming requests enter a shared continuous batch:
The Two Contrasting Regimes
| Metric / Attribute | Prefill Phase (Prompt Processing) | Decode Phase (Token Generation) |
|---|---|---|
| Operational Bottleneck | Compute-Bound (Matrix-Matrix GEMM) | Memory-Bandwidth-Bound (Matrix-Vector GEMV) |
| Arithmetic Intensity | High (~100 to 250 FLOP/byte) | Extremely Low (~1 to 2 FLOP/byte) |
| Primary User Metric | Time-To-First-Token (TTFT) | Inter-Token Latency (ITL) / Tokens-Per-Sec |
| Optimal Hardware Setup | High compute density, lower Tensor Parallelism | Maximum HBM bandwidth, higher Tensor Parallelism |
When a 4,096-token prefill shares a forward pass with ongoing decode requests, the forward pass time jumps from 15ms to 400ms. To the user reading streamed text, generation suddenly freezes—violating real-time voice and streaming Service Level Objectives (SLOs).
2. Prefill-Decode (PD) Disaggregated Serving Architecture
Disaggregated serving (pioneered by systems like Splitwise, DistServe, Mooncake, and NVIDIA Dynamo) physically splits the inference pipeline across specialized hardware nodes:
How Disaggregation Works
- Prompt Ingestion: The router receives an incoming prompt sequence.
- Dedicated Prefill Execution: A prefill worker executes the full causal prompt pass in parallel, computing the prompt KV cache and sampling the first output token.
- KV Cache Transfer: The prefill worker transfers the completed KV cache across the high-speed network fabric (InfiniBand, RoCE v2, or NVLink) directly into the decode worker's physical memory pool.
- Isolated Decode Loop: The decode worker appends the first token, assumes ownership of the request, and performs continuous autoregressive decoding with zero compute interference.
Conditional Disaggregation
In production clusters, transferring small KV caches introduces network serialization overhead. Systems use Conditional Disaggregation:
- Short prompts ( tokens): Executed locally on the decode worker to avoid network transfer latency.
- Long prompts ( tokens): Dispatched to dedicated prefill workers to protect decode workers from head-of-line blocking.
3. Prefix Caching & Radix Tree Management
Modern agentic workflows, long-document RAG, and multi-turn conversations reuse massive amounts of prompt text. Re-running prefill on identical tokens burns expensive compute and spikes TTFT.
Prefix Caching retains the KV cache of previously processed tokens in memory across independent requests.
RadixAttention (SGLang & vLLM APC)
Rather than storing independent linear prompt caches, state-of-the-art inference engines organize KV cache blocks as a Radix Tree (a space-optimized Trie):
- Prefix Sharing: Any node in the tree can be shared by thousands of active requests.
- LRU Eviction: When GPU memory pressure rises, an LRU (Least Recently Used) policy evicts leaf nodes while preserving high-frequency ancestor nodes (like core system prompts).
- Cache-Aware Routing: The cluster load balancer hashes the prompt prefix and routes incoming requests to the specific GPU worker whose local memory already contains that Radix branch.
4. Distributed Model Parallelism: TP vs PP vs EP
When frontier models exceed the memory capacity of a single GPU (e.g., DeepSeek-V3 with 671 billion parameters requires GB for FP8 weights alone), inference must be partitioned across multiple GPUs.
DeepSeek-V3 & Frontier MoE Inference Architecture
Frontier MoE models like DeepSeek-V3 (671B total parameters, 37B active parameters per token) require Dual-Topology Parallelism:
- Attention Layers: Replicated or sharded via Tensor Parallelism () across dense intra-node NVLink.
- Expert Layers: Sharded via Expert Parallelism ( or ) across multiple nodes connected via RoCE/InfiniBand.
- Multi-Head Latent Attention (MLA): Compresses the KV cache into a low-dimensional latent space (), reducing KV cache memory footprint by to compared to standard MHA/GQA.
5. Production Latency Metrics & Sizing Equation
In production inference engineering, system performance is governed by strict Service Level Agreements (SLAs).
- Time-To-First-Token (TTFT): Latency from HTTP request arrival to the emission of the first token. Dominated by queueing delay and prefill GEMM speed.
- Inter-Token Latency (ITL): Time between consecutive streamed tokens. Dominated by GPU memory bandwidth and decode Tensor Parallelism.
- Time-Per-Output-Token (TPOT): Average duration per output token across the entire sequence.
GPU VRAM Allocation Sizing Formula
To determine the minimum number of GPUs required to serve a model under concurrent load:
6. Python Simulation: Prefix Radix Tree Cache Simulator
Run this live in-browser Python implementation to simulate how a Radix Tree cache eliminates redundant prefill compute across multi-turn agent interactions:
Decouple compute-bound prefill from memory-bound decode. As context windows scale to 128k+ tokens, monolithic serving guarantees severe tail-latency violations. Deploy disaggregated architectures and Radix prefix caching to achieve deterministic, rock-solid sub-20ms streaming latency.
You have mastered the complete systems stack of Inference Engineering: from low-level GPU SRAM kernels and INT4 quantization, to ultra-low-power TinyML microcontroller arenas, up to hyperscale disaggregated cloud serving clusters. Return to the Inference Engineering Roadmap to review the full curriculum.