Unit 5 of 11 · about 4 hours · explain, implement
Replica routing, load balance and cache-locality skew
A warm prefix saves prefill work but can attract enough requests to overload its owner. Routing must value the saved work against waiting and capacity, not maximize hits alone.
You'll be able to
- Implement a deterministic cache-aware router that checks capacity before applying locality and load tie-breaks.
- Compare load-only and cache-aware decisions under hot-prefix skew, changing reuse and stale worker information.
- Diagnose a higher cache-hit rate that worsens queueing, fairness or SLO-qualified completions.
Covers
Read
In this order, only the parts listed
0 of 3 done
- Routing independent serving replicasHands-On LLM Serving and Optimization - Chapter 7, multi-GPU and disaggregation
Chapter 7, Data Parallelism, printed pp. 244 to 245 - round robin, least connections, latency-based and cache-aware routing
- Balance predicted waiting against cache reuseMooncake: A KVCache-Centric Disaggregated Architecture for LLM Serving
FAST 25 paper, Section 4.1 Prefill Global Scheduling and Section 4.2 Cache Load Balancing, printed pp. 161 to 162
Study the decision rule and hot-cache replication. Leave the cluster experiments and their numerical results out of your local routing claims.
- Worker selection at phase boundariesNVIDIA Dynamo - Disaggregated Serving and KV-Aware Routing
Dynamo v1.5.1, Efficient KV Transfer - Router Orchestration, steps 1 to 4
Focus on
- Build on Exact prefix identity, version scope and tenant privacy scope. A cache overlap score is useful only for compatible, authorized KV; it is not permission to reuse another tenant's state.
- Track full assigned token capacity separately from uncached prefill work. Reuse saves computation but does not make the destination request's complete context disappear.
- The TensorTonic problem prioritizes the longest cached prefix before projected uncached load. Mooncake instead minimizes predicted TTFT including waiting; these are different policies, not equivalent implementations.
- Worker discovery, cache events and load estimates can lag. Revalidate capacity and identity at admission, and keep a fallback for evicted prefixes or unavailable workers.
Common mistakes · 3
- Using uncached tokens as the memory-admission cost. The public rule admits against the full assigned request length even when most tokens have a prefix hit.
- Interpreting a router's hit estimate as guaranteed resident KV. Eviction or worker restart between selection and admission can invalidate it.
- Improving aggregate TTFT while starving tenants with cold prefixes. Compare waiting and completions by tenant or request class.
Try it yourself
Closed-book, before checking anything
[10, 8], prefix lengths [[8, 0], [0, 6]], worker IDs [2, 1] and capacities [20, 20]: assignments [2, 1] and uncached loads [2, 2]. Then construct a queued hot-prefix case where a predicted-TTFT policy deliberately chooses less reuse.Quiz yourself
Answer first, then mark it. Missed ones go to Review.
0 got · 0 missed
1.A six-token request has a four-token cache hit on a worker with capacity five. Is it feasible under the problem's rule?Answer
No. Full assigned length, six tokens, exceeds capacity five. The two uncached tokens determine compute load, not feasibility.
2.Why can longest-prefix routing lose to load-only routing?Answer
A hot cache owner can have enough waiting work to outweigh the saved prefill. Low reuse or stale cache information can also remove the expected saving.
3.Two workers tie on prefix, projected work and remaining capacity. What breaks the public problem's tie?Answer
The smaller worker ID, not the first worker in the input array. Returned loads remain in input-worker order.
4.Does replicating a hot prefix always improve goodput?Answer
No. It costs memory and transfer work, can evict useful other prefixes and may not relieve the current compute or queue bottleneck. Test it on the same arrival trace.
Practice
- TensorTonic: Route Cache-Aware Prefill Requests
Implement
cache_aware_prefill_routing(request_token_counts, cached_prefix_lengths, worker_ids, worker_capacities)The free public cases check cache-local choices, worker-ID tie-breaking and rejection when no worker fits. Add tests for projected-load and remaining-capacity ties yourself. The section mini-project compares this locality-first rule with load-only and predicted-TTFT routing.
You're done when
Your router passes the three public cases and your additional tie-break tests, and your hot-prefix counterexample explains why saved prefill does not guarantee lower waiting or better goodput.
Only when you can do this without notes.
Leads to
Notes
Resources · 3 for this unit, 10 more in the section
- Hands-On LLM Serving and Optimization - Chapter 7, multi-GPU and disaggregationChi Wang and Peiheng Hu (O'Reilly) · support
Read "Multi-GPU and Multi-Node Inferencing" (data, tensor, pipeline and expert parallelism) and "Prefill-Decode Disaggregation" (architecture, KV transfer, when to use it) in Chapter 7.
- NVIDIA Dynamo - Disaggregated Serving and KV-Aware RoutingNVIDIA · required
Trace frontend, prefill router, prefill worker, KV transfer, decode routing and decode worker. Record how load, cache overlap, worker discovery and transfer metadata affect placement; implement only a small simulated or available-hardware slice.
- Mooncake: A KVCache-Centric Disaggregated Architecture for LLM ServingMoonshot AI · support
Read the KV-centric architecture, transfer engine and scheduling sections to understand remote cache pools. Compare its assumptions with DistServe and your simpler handoff; defer reproduction requiring a large cluster.
Also in this section
- DistServe: Disaggregating Prefill and Decoding for Goodput-Optimized LLM ServingPeking University and Microsoft Research · primary
Read the interference model, independent phase parallelism, placement, KV transfer and goodput evaluation. Reuse the break-even method with your workload and topology; do not transfer the paper's speedups to different hardware.
- AI Systems Performance Engineering - Chapters 15 and 17, distributed and disaggregated inferenceChris Fregly (O'Reilly) · required
Read the disaggregated prefill and decode architecture and the MoE parallelism strategies in Chapter 15, then Chapter 17 on disaggregated pools, routing policies and scalability. Reproduce every communication and KV-transfer estimate for a small declared topology.
- AI Systems Performance Engineering companion code - Chapters 15 and 17Chris Fregly · required
Use the single-device KV-handoff and simulation paths before the multi-GPU pairs. Then choose one disaggregation, routing or MoE target compatible with available hardware and keep bundled results separate from newly captured evidence.
- TensorRT-LLM Disaggregated Serving and KV Cache ExchangeNVIDIA · required
Study the KV exchange abstraction, unique request identity, layout conversion, overlap and fleet-worker model. Use its reproducible benchmark sections only on supported hardware and pin the release.
- SGLang documentation - PD DisaggregationSGLang Project · support
Use the transfer backends, router integration, heartbeat, timeout and cleanup behavior as a second engine's view of the same handoff.
- 100 Days of LLM Inference - Days 12, 17 and 18Elizabeth Thomas · support
Use the Dynamo, model-parallelism and disaggregation notebooks for a compact topology simulator and request-handoff trace. Label notebook outputs as local analytical or simulated evidence unless real devices were used.
- TensorTonic Language Modeling from Scratch - Route Cache-Aware Prefill RequestsTensorTonic · support
Solve after the routing unit and compare its cost rule with your own placement model.
- LLM Inference: From scratch, one token at a time - Module 09Tushar Amrit · support
Work the Distributed Inference module's communication arithmetic before the tensor and pipeline parallel units.
- AI Performance Engineering - Distributed InferenceWafer · reference
A curated index. Use Section 5 only to find a distributed-serving paper the other entries lack.
- Python 3.14 hashlib - byte digests for KV integrity checksPython Software Foundation · reference
Usage and Hash Objects only: compute and compare a SHA-256 digest over a declared canonical KV payload. Add request/version checks separately; a byte digest is not cache compatibility or authentication.