All insights

LLM Prefix Aware Routing: When Cache Locality Beats Load Balancing

LLM prefix aware routing can cut time to first token when long prompts repeat, but strict affinity can overload a worker. The useful policy trades cache reuse against queueing delay.

By Cloudex Research Desk, AI Systems Practice, Cloudex Technologies

Key takeaways

  • Prefix caching delivers fleet-level value only when requests with shared prefixes reach replicas that still hold the corresponding KV state.
  • AWS reported 71–77% lower median time to first token for 8,000-token shared prefixes, but only 13–16% for shorter conversation workloads.
  • Strict prefix affinity can worsen tail latency when a popular prefix concentrates requests on one worker.
  • The deployment decision should use replayed traffic, token-level prefix overlap, queue time, cache-hit tokens and tail latency rather than cache-hit rate alone.

Why LLM prefix aware routing depends on cache locality

LLM prefix aware routing is useful only when repeated prefixes reach a replica that still holds their KV state. A cache-enabled engine behind a locality-blind router can therefore deliver almost no fleet-level benefit, even though prefix caching works correctly on every worker.

During prefill, a transformer computes key and value tensors for every prompt token. If a later request begins with the same token sequence, the engine can reuse those tensors and process only the new suffix. vLLM's Automatic Prefix Caching documentation is explicit about the boundary: reuse reduces prefill work, not the time spent decoding new output tokens.

That distinction matters in distributed LLM serving. Suppose eight replicas each receive one eighth of requests carrying the same 8,000-token policy document. Random routing makes each replica build and retain its own copy. Sparse reuse and eviction can erase the expected gain. Keeping that prefix on one worker raises the hit rate, but sending every matching request there can overload it.

The router must solve both problems. It needs enough affinity to preserve cache locality and enough freedom to move work when a preferred replica is busy. Prefix-aware routing is therefore a scheduling policy, not a cache feature.

This affects systems with stable, repeated context: document question answering, multi-turn sessions, code completion and tool-using agents. It can also matter for AI employees, where the same operating policy, tool schema or account context may appear at the start of many requests. It does little for unrelated prompts or workloads dominated by long generated answers.

The router needs a map of prefixes, caches and load

A basic implementation hashes the first part of a request and uses consistent hashing to select a replica. Requests with the same routing key usually return to the same worker. AWS uses a related stability property to limit traffic movement when instances join or leave its prefix-aware routing service.

Hash affinity is cheap, but it is incomplete. The router may not know whether the selected worker still holds the matching KV blocks. It may also treat two requests as equivalent when their tokenised prefixes differ after a hidden template change.

A stronger design tracks cache state. Each worker reports which prefix blocks it holds, how much reusable context matches an incoming request, and its current queue or estimated compute load. The router then scores candidate workers using two competing costs:

  1. Prefill work avoided by a cache hit.
  2. Waiting time and eviction cost added by choosing a busy worker.

The Preble paper formalises this as exploitation versus exploration. Its E2 scheduler exploits the worker with the longest matching prefix when saved recomputation exceeds new computation. Otherwise, it explores the least-loaded worker. Its load estimate includes recent prefill and decode time, the cost of KV eviction, and the cost of the new request.

This is more precise than counting in-flight requests. A request with a 16,000-token cache miss is not equivalent to one with a 15,000-token hit and a 1,000-token suffix. Queue depth alone hides that difference.

Inside a worker, the cache still needs its own data structure and eviction policy. SGLang's RadixAttention design stores token sequences in a radix tree and evicts least-recently-used leaf nodes. Prefix search, insertion and eviction happen locally. The distributed router decides which local tree gets the next opportunity to reuse a branch.

Locality and load pull in opposite directions

The correct policy depends on traffic shape. No single routing rule wins across all loads.

Random routing

Random routing provides low cache locality when repeated prefixes are distributed across many replicas. It responds well to load on average, but several workers may recompute the same prefix. It best suits workloads with little prefix repetition or traffic dominated by decoding.

Least-outstanding-requests routing

Least-outstanding-requests routing responds strongly to variable service times but usually provides poor cache locality. It can send a request away from a warm worker to a cold but idle one. It best suits unpredictable requests with little reusable context.

Sticky hashing

Sticky hashing provides high locality while fleet membership remains stable. Its load response is weak unless the router supports overflow. A popular prefix can create a hot worker, so the policy works best when traffic is spread across many balanced prefix groups.

Cache-aware routing with overflow

Cache-aware routing preserves locality until the preferred worker crosses an overload threshold. It can respond well to bursts when its load estimates are accurate. Spillover duplicates KV state and can lower the hit rate, but the policy fits long shared prefixes with bursty demand.

Cost-based scheduling

Cost-based scheduling can provide the highest locality while explicitly trading reuse against waiting time. It requires more metadata, scoring logic and failure handling. The added complexity is most defensible in large fleets where prefill cost dominates.

The hard case is a hot prefix. Strict affinity sends every matching request to one replica, increasing queueing delay while other GPUs sit idle. Immediate spillover fixes the queue but warms another cache. A practical router needs a threshold, hysteresis or a cost model so it does not oscillate between replicas.

Preble addresses this by detecting load changes and replicating a popular prefix across GPUs when one worker cannot carry the demand. Its paper also reports a finite control-plane limit: the global scheduler processed 245 ToolBench requests per second for a complex prefix tree and 2,931 VideoQA requests per second for a simpler one. The authors estimated one scheduler could sustain at least 70 to 391 concurrent A100 GPUs under their stated assumptions. Those figures are architecture-specific, not a universal capacity target.

The router also needs a stable definition of sameness. Raw JSON bytes, rendered text and token IDs produce different routing keys. AWS warns that whitespace, key ordering and formatting affect routing when its native API hashes request bytes. A temperature field placed before the shared text can split otherwise identical prompts. Canonical serialization and a versioned prompt template are operational requirements, not housekeeping.

Published gains are large, but workload-specific

The strongest recent production-style evidence comes from an AWS SageMaker benchmark published in September 2026. AWS tested Llama 3.1 70B Instruct with vLLM across seven ml.p5.48xlarge instances and 16 endpoint configurations.

For one-hour tests with 8,000-token shared prefixes, AWS reported 71–77% lower P50 time to first token, 33–37% lower P90 TTFT, and 15–16% higher throughput. KV-cache hit rate rose from roughly 25% to 82%. Its routing layer added 1.3–1.9 milliseconds per request while measured model TTFT ranged from 63 to 280 milliseconds.

The short-context result was much smaller. In 30-minute ShareGPT-style conversation tests, P50 TTFT fell 13–16%, P90 fell 24–37%, and throughput improved only 1.7–2.0%. The comparison shows why cache hit rate alone is insufficient. A hit on a short prefix can have little economic value.

Preble offers broader research evidence, although on older and smaller testbeds. The authors evaluated Mistral 7B and Llama 3 70B on four NVIDIA A6000 GPUs and eight H100 GPUs. Across five workloads and an Azure arrival trace, they reported 1.5–14.5 times lower average latency and 2–10 times lower P99 latency than state-of-the-art serving baselines. Their workload study found prompts were 37–2,494 times longer than outputs and that 85–97% of prompt tokens were shared. These are selected benchmark workloads, not measurements of general production traffic.

Single-worker results establish the value of reuse but do not prove a distributed router. The revised SGLang paper reports up to 6.4 times higher throughput than comparison systems across language and multimodal tasks. RadixAttention was one of several optimisations, alongside structured-decoding and execution improvements. The number should not be attributed to routing or prefix caching alone.

No public benchmark here covers every combination of model, quantisation, GPU, concurrency, prompt churn and service-level objective. The safe conclusion is narrower: locality can cut TTFT sharply when long prefixes repeat, but the gain must be measured against queueing and cache churn on the target workload.

Failure modes appear above and below the router

Prefix-aware routing can fail even when its matching algorithm is sound.

  • Prompt drift lowers reuse. Changing a system prompt, tool order, JSON schema or whitespace can invalidate every downstream token in the prefix.
  • Cache churn removes state before reuse. Large unique prompts, small KV capacity or aggressive batching can evict a valuable prefix.
  • Hot keys create queues. A tenant, document or agent policy can become popular enough that affinity harms tail latency.
  • Autoscaling starts cold. New replicas have empty caches. Moving traffic too quickly can raise TTFT during the event that was meant to relieve load.
  • Stale cache metadata misroutes work. A control plane may believe a prefix exists after eviction or worker restart.
  • Tenant boundaries complicate sharing. Identical text does not imply that two tenants should share a routing or cache domain.
  • Decode-heavy requests mask prefill savings. vLLM notes that automatic prefix caching brings little gain when generation dominates total work.

AWS exposes two controls that illustrate the operational trade-off. PrefixLength chooses how much request content participates in routing, and ConcurrencyThreshold sends overflow to another instance. The documented ranges are 1,024–65,536 for prefix length and 1–1,024 for the concurrency threshold. A short key can create a hot spot; a long key can fragment a reusable group.

Security and correctness need separate treatment. Route requests only within cache namespaces that bind token sequences to the model, adapter, prompt-template version and tenant policy. Avoid logging raw prefixes, and use explicit tenant isolation where cache relationships should remain separate. AWS provides an optional tenant identifier so identical prompts from different tenants can route independently.

Decide with traces, not a feature checklist

Adopt LLM prefix aware routing when repeated prefill is material and measurable. Do not add it because the serving engine exposes a prefix-cache flag.

Start with a seven-day trace, sampled or replayed under the required privacy controls. Measure prefix overlap at the token-block granularity used by the engine. Then record cache-hit tokens, uncached prefill tokens, TTFT, inter-token latency, queue time, eviction rate, output length and replica skew.

Run three policies against the same arrival pattern: the current router, sticky prefix hashing, and cache-aware routing with overload protection. Test at normal load and near the latency SLO. Report P50, P95 and P99 rather than an average alone. Include scale-out, worker restart, template deployment and one deliberately hot prefix.

A deployment case is credible when it clears four gates:

  1. Shared prefixes are long enough and frequent enough to remove meaningful prefill work.
  2. TTFT or GPU-seconds improve at the target concurrency, not only in an unloaded test.
  3. P99 latency remains within the SLO when affinity concentrates demand.
  4. The gain survives prompt releases, autoscaling and cache eviction.

This evaluation belongs in the acceptance criteria for custom LLM pipelines and automation. It also complements two-gate acceptance testing for custom AI integrations: verify the technical mechanism, then verify the business outcome. A higher cache-hit ratio is an intermediate metric. Lower latency, higher goodput or fewer GPU-hours is the result.

If long shared prefixes account for little prefill time, keep the simpler router. If they dominate and tail latency improves under realistic load, deploy locality gradually with overflow enabled. For a workload-specific review of routing traces, cache metrics and deployment constraints, start a conversation.

Frequently asked questions

What is LLM prefix aware routing?

LLM prefix aware routing sends requests with matching prompt prefixes to workers likely to hold the corresponding KV cache. This lets the worker skip repeated prefill computation. A production router must also consider queue length, cache eviction and worker capacity so that locality does not create an overloaded replica.

Does prefix-aware routing reduce all LLM inference latency?

No. It mainly reduces time to first token by avoiding repeated prefill work. It does not accelerate the decoding of new output tokens. The gain is therefore largest when prompts contain long repeated prefixes and outputs are relatively short. Unrelated prompts and decode-heavy workloads may show little improvement.

How should a prefix-routing key be chosen?

The key should cover enough stable prompt content to distinguish reusable workloads without including variable fields that fragment them. Canonicalise JSON, keep prompt templates versioned, and exclude volatile metadata where the platform permits it. Then test for hot keys, because a key shared by too much traffic can overload one worker.

When is KV cache routing worth the added complexity?

KV cache routing is worth testing when repeated prefixes account for a material share of prefill tokens and TTFT affects the service objective or GPU cost. Replay real arrival patterns and compare the current router, sticky hashing and cache-aware routing. Proceed only if tail latency and GPU-seconds improve after overload, autoscaling and cache-eviction tests.

Sources

  1. 1Reduce LLM latency with prefix-aware routing on Amazon SageMaker InferenceAmazon Web Services · 10 Sept 2026
  2. 2Preble: Efficient Distributed Prompt Scheduling for LLM ServingVikranth Srivatsa, Zijian He, Reyna Abhyankar, Dongming Li and Yiying Zhang · 8 May 2024
  3. 3Automatic Prefix CachingvLLM
  4. 4Fast and Expressive LLM Inference with RadixAttention and SGLangLMSYS Org · 17 Jan 2024
  5. 5SGLang: Efficient Execution of Structured Language Model ProgramsLianmin Zheng et al. · 12 Dec 2023
Cloudex Research Desk
AI Systems Practice, Cloudex Technologies

The Cloudex Research Desk tracks primary sources across AI research, model releases and production tooling, and publishes analysis reviewed against those sources before it goes live. Every claim links to where it came from.

Thinking about applying this in your business?

Cloudex designs and ships AI employees, custom software, and growth systems for teams that need the theory turned into something that runs in production.

Start a conversation