Applications built on large language models often send prompts made of two parts: a long fixed block of instructions or context, and a short variable part with the actual user input. A customer service bot might repeat the same 3,000-token policy text with every request, followed by a 50-token question. When that fixed block gets processed from scratch on every call, it adds unnecessary computation and delay.
Serving frameworks such as vLLM and TensorRT-LLM already address part of this problem with prefix caching, a technique that stores the computed key-value (KV) pairs for a prompt’s repeated beginning so the model does not recompute it on the next matching request. This works well on a single machine. AWS explains that the trouble starts once traffic is spread across a fleet of instances: the standard random routing method sends each request to whichever instance is available, so the same 3,000-token prefix might land on a different machine every time. No single instance sees the prefix often enough to build a useful cache, even though the caching feature is technically active.
What Prefix-Aware Routing Changes
Amazon SageMaker Inference now offers a routing strategy called PREFIX_AWARE, AWS says, which looks at the beginning of each incoming request and consistently sends matching prefixes to the same instance. If ten requests share an opening block of text, all ten are directed to the same machine, letting that instance’s cache stay warm instead of being rebuilt each time. AWS states that no manual tagging or affinity configuration is required; the endpoint determines routing based on the request content itself.
Two safeguards are built into the feature, according to AWS. Overload protection reroutes a request to a less busy instance if the target machine has reached a configured concurrency limit, trading a potential cache hit for stability. A second mechanism keeps routing behavior stable when the instance fleet scales up or down, shifting only a small portion of traffic rather than invalidating caches across the board.
Benchmark Results Reported by AWS
AWS reports benchmark testing using Llama 3.1 70B Instruct on seven ml.p5.48xlarge instances running vLLM with prefix caching enabled, comparing prefix-aware routing against the default random routing baseline across 16 configurations. All test runs reportedly completed with a 100 percent success rate.
For long-context workloads using 8,000-token shared prefixes sustained over an hour, AWS reports P50 time-to-first-token (TTFT) reductions of 71 to 77 percent and P90 reductions of 33 to 37 percent. KV cache hit rates reportedly rose from around 25 percent to as high as 82 percent, with throughput increasing 15 to 16 percent.
Short-context workloads using variable-length, ShareGPT-style conversations over 30 minutes showed smaller but still measurable gains: P50 TTFT reductions of 13 to 16 percent, P90 reductions of 24 to 37 percent, and cache hit rates rising from roughly 30 to 80 percent. AWS attributes the size difference to the length of the shared prefix — longer shared blocks mean more computation can be skipped per cache hit, while shorter prefixes yield proportionally smaller savings.
AWS also reports that the routing logic itself adds only 1.3 to 1.9 milliseconds of overhead per request, against a measured model TTFT range of 63 to 280 milliseconds, and that traffic stayed evenly balanced across all seven instances, each receiving between 13.3 and 15.4 percent of requests.
Three Routing Strategies Now Available
With this addition, SageMaker Inference offers three routing options for real-time endpoints, per AWS’s documentation. RANDOM remains the default, distributing requests evenly and suiting general-purpose or non-LLM workloads where requests are interchangeable. LEAST_OUTSTANDING_REQUESTS sends each request to whichever instance currently has the fewest in-flight requests, useful when processing times vary widely. PREFIX_AWARE is the new option, aimed specifically at LLM workloads where many requests share text at the start and the serving framework has prefix caching turned on.
AWS notes that the strategy is set per production variant in the endpoint configuration and can be switched without redeploying the underlying model.
Where the Gains Apply
AWS points to several patterns where shared prefixes are common. Retrieval-augmented generation (RAG) applications prepend a retrieved document before the user’s question, so multiple users asking about the same document share that document as a prefix. Multi-turn conversations accumulate shared history with every turn, making the prefix longer as a conversation progresses. Bots built on long, structured instruction blocks — policies, formatting rules, persona definitions — send that same block with every message, so processing it once instead of repeatedly reduces redundant computation. Code completion tools that include file contents as context also benefit while a developer continues working within the same file.
Configuration Details Worth Checking
Two parameters control the feature’s behavior, according to AWS’s documentation. PrefixLength, ranging from 1024 to 65536, determines how much of a request is used for routing decisions — bytes from the start of the body for the native Invoke API, or characters of extracted message text for the OpenAI-compatible API. ConcurrencyThreshold, ranging from 1 to 1024, sets the maximum in-flight requests an instance can hold before overflow routing activates.
Teams evaluating this feature should confirm their serving framework has prefix caching enabled, since prefix-aware routing depends on that underlying mechanism to produce any benefit. It is also worth checking whether prompt structures in a given application actually share meaningful text at the start; workloads without repeated prefixes are unlikely to see the reported gains. The benchmarks were run on a specific instance type and model, so results may vary with different hardware or model sizes not covered in AWS’s reported tests.
What Remains Unclear
AWS’s benchmark figures come from its own testing on a single model and instance configuration, without independent verification. Whether comparable latency reductions hold for smaller models, different GPU instance types, or mixed workloads outside the tested scenarios has not been established.