Education › Inference › Stage 6: Distributed inference architecture

Designing around data movement

KV-aware routing, cache tiers, placement and topology — architecture driven by where bytes have to travel.

Advanced ~35 min read Module 12 of 15

At cluster scale, the expensive thing is rarely arithmetic; it is moving bytes. Prompts that are recomputed because they landed on the wrong replica, KV caches that cross a slow link, weights that take minutes to load, and model shards placed across racks all burn time and money. This lesson turns that into design rules: route requests to where their data already is, tier the KV cache, place model replicas to match the network topology, and use Kubernetes building blocks made for inference rather than generic load balancing.

After this module you can
  • Explain why round-robin load balancing wastes work for LLM traffic
  • Design KV-aware and session-aware routing with an inference gateway
  • Use a KV-cache hierarchy from GPU memory to remote storage
  • Place multi-GPU replicas to match NVLink domains, racks and nodes
  • Draw a data-movement budget for a request and find the dominant transfer

Route to where the data already is

A web load balancer spreads requests evenly and assumes any replica is as good as another. For LLMs that assumption is wrong: a replica that already holds a conversation's history or a shared system prompt in its KV cache can skip most of the prefill. Round-robin destroys that locality, so every replica keeps recomputing the same prefixes.

  • Session affinity sends a conversation's turns to the same replica. Simple, but it ignores load and breaks when the replica is busy or gone.
  • KV-aware routing hashes prompt prefixes into blocks, tracks which replica holds which blocks, and scores replicas by cache overlap and current load. Dynamo's router and the llm-d inference scheduler do this.
  • Load- and queue-aware routing uses each replica's waiting requests and cache usage, which the engines expose as metrics, to avoid hot spots even without cache overlap.
  • Adapter-aware routing sends requests for a LoRA adapter to replicas that already have it loaded.

On Kubernetes, the Gateway API Inference Extension standardises this: an InferencePool groups the model-server pods, and an endpoint picker called by the gateway (through Envoy's external processing) chooses the best pod per request using engine metrics such as queue length and prefix-cache state.

requestroutebest replicaoffload, reloadClientsAI gatewaytenants, limitsEndpoint pickercache + queue awareReplica Ano prefix cachedReplica Bprefix cachedCache tierDRAM, NVMe, shared
Route to where the data already is: the gateway applies tenant policy, the endpoint picker chooses the replica holding the prompt's prefix, and cold cache can be fetched from a lower tier.
An InferencePool: the pods to route across, and the endpoint picker to consult
yaml
apiVersion: inference.networking.k8s.io/v1
kind: InferencePool
metadata:
  name: chat-pool
spec:
  selector:
    matchLabels:
      app: vllm-chat
  targetPorts:
    - number: 8000
  endpointPickerRef:
    name: chat-epp
    port:
      number: 9002
    failureMode: FailOpen

Tier the KV cache

GPU memory is the fastest and smallest place for KV cache. When it is full, the choice is to evict and later recompute (spending GPU time) or to move blocks to a cheaper tier and bring them back (spending bandwidth). For long, idle conversations and shared documents, keeping cache is usually cheaper than recomputing it.

TierCapacityReachGood for
GPU HBMSmallestFastestActive sequences
CPU DRAMSeveral times largerOver PCIeRecently idle conversations
Local NVMeMuch largerSlower, still localLong-lived prefixes on this node
Shared or object storageEffectively unlimitedOver the networkCache shared across nodes, warm restarts

Tools such as Dynamo's KV Block Manager, LMCache and vLLM's offloading connector implement these tiers. Combined with KV-aware routing, a cluster can behave like one large cache: a request goes where its prefix is, and if no GPU has it, a node can fetch it from a lower tier instead of recomputing.

Place replicas to match the topology

  • Keep each tensor-parallel group inside one NVLink domain: one node, or a rack-scale NVLink system.
  • Place pipeline stages and disaggregated prefill/decode pairs on nodes with fast RDMA paths between them, ideally the same rack or network spine.
  • Schedule multi-pod replicas as a unit: all pods start together or none do. LeaderWorkerSet in Kubernetes deploys a group of pods as one unit of replication; topology-aware gang schedulers such as Grove add rack and NVLink-domain placement.
  • Spread whole replicas across failure domains for availability, but never split one replica across them.
  • Keep weights close to the GPUs (node-local caches, pre-pulled images) so scaling out does not wait on downloads.

A data-movement budget

For any design, list every transfer a request causes, its size and the link it uses, and estimate its time. The largest line is where to spend design effort.

TransferTypical sizeLink
Prompt and response textKilobytesClient network
TP all-reduces per decode stepHundreds of KiB, many times per stepNVLink
KV handoff (disaggregated)Hundreds of MiB per long promptRDMA or NVLink
KV fetch from lower tierUp to the size of the prefixPCIe, NVMe or network
Weights on scale-outTens to hundreds of GB per replicaStorage and PCIe
Tip

Draw the budget before choosing tools. Teams often adopt disaggregation or cache offload when their dominant cost was actually cold-start weight loading or a gateway that ignores cache locality.

Hands-on practice

Measure the value of locality

  1. Run two replicas of the same engine on two GPUs with prefix caching on.
  2. Put a plain round-robin proxy (for example nginx with two upstreams) in front and replay 50 multi-turn conversations; record TTFT per turn.
  3. Switch the proxy to hash on a conversation ID header (session affinity) and replay; compare TTFT for later turns.
  4. If available, try a KV-aware router (Dynamo frontend with --router-mode kv) and replay again.
  5. Write the data-movement budget for one 20-turn conversation under each setup.
  6. Summarise which routing you would deploy and the evidence.
Cheat sheet

Designing around data movement — at a glance

Main things to focus on

  • Bytes, not FLOPs, dominate cluster-scale cost: design for data movement.
  • Round-robin destroys prefix locality; route by cache overlap and load.
  • InferencePool plus endpoint picker is the Kubernetes standard for inference routing.
  • Tier KV cache from HBM to DRAM, NVMe and shared storage.
  • Keep TP groups in one NVLink domain; gang-schedule multi-pod replicas.
  • Write a data-movement budget and attack the largest line.

Routing strategies

round-robinEven spread, ignores cache: wasteful for LLMs
session affinitySame replica per conversation; ignores load
KV-awareScore by prefix-cache overlap and load
queue-awareAvoid replicas with long waiting queues
adapter-awarePrefer replicas with the LoRA already loaded

Kubernetes building blocks

kind: InferencePool (inference.networking.k8s.io/v1)Pods to route across, plus endpoint picker
endpointPickerRefService that chooses the pod per request
LeaderWorkerSetDeploy a multi-pod replica as one unit
failureMode: FailOpenFall back to plain routing if the picker is down

Cache tiers

HBM -> DRAM -> NVMe -> shared storageFast/small to slow/large
evict + recompute vs offload + reloadGPU time vs bandwidth
KVBM / LMCache / OffloadingConnectorImplementations

Placement rules

TP group within NVLink domainNever across nodes over Ethernet
PP stages and P/D pairs on fast RDMA pathsSame rack or spine
spread replicas, not shards, across zonesAvailability without slow links

Common pitfalls

  • Generic round-robin load balancing in front of LLM replicas.
  • Session affinity that sends every turn to an overloaded replica.
  • Splitting one replica's shards across racks or zones.
  • Recomputing long idle conversations when offload would be cheaper.
  • Adopting complex infrastructure without a data-movement budget.
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 →