AI infrastructure

When SageMaker KV Cache Routing Helps

Decide when SageMaker cache-aware routing is worth testing, and compare the wait for a first token on fresh documents and follow-up questions.
By MR Solutions
4 min readPublished
Amber tiles line up with the matching middle tray between rows of teal and cream tiles.

Why a follow-up question can keep someone waiting

A support analyst asks a second question about a long policy document. The assistant sends the policy again, followed by the conversation so far. On a SageMaker endpoint with several model instances, the analyst’s wait for the first word can depend on which instance receives that follow-up.

Processing the start of a prompt leaves intermediate results in the model’s key-value (KV) cache. An instance that still holds those results can skip work on the matching tokens. The opportunity is greatest when a substantial opening passage recurs before it is evicted. Count how often that happens in a typical shift before budgeting for a trial.

Choose a baseline that fits the traffic

For short, unrelated requests, random routing gives a simple baseline. Where request durations vary, also consider routing to the instance with the fewest outstanding requests. A longer prompt offers little scope for reuse if its opening changes every time.

For a stable shared opening, prefix-aware routing sends requests with the same configured prefix to the same destination, subject to load. This can work well for a common policy at moderate demand. Under memory pressure the destination may have discarded the policy, and the router has no cache report to tell it so.

KV-aware routing uses reports of additions and evictions to find the available instance with the best balance of matching tokens and load. That helps when conversation histories grow or different instances retain different lengths of a document. Looking up the match takes time, including tokenising the prompt. Short matches leave less work to offset that cost.

What the 97% figure measures

In its 17 November 2026 launch report, AWS measured up to 97% lower median time to first token against random routing. It served Llama 3.1 70B Instruct on seven ml.p5.48xlarge instances in 30-minute runs with 20 or 100 simulated users and prompts reaching roughly 64,000 tokens. The largest gains came with long prompts under load.

A smaller AWS trial makes the trade-off visible. In one paired run, the median wait for questions two to four fell from 1,284 ms with random routing to 237 ms with KV-aware routing. Meanwhile, average endpoint overhead outside the model container rose from 13.1 ms to 27.1 ms. Those follow-ups reused long documents. A team already using prefix-aware routing still needs to measure the incremental gain over its own baseline.

Replay one shift three ways

Check eligibility first. At launch AWS specified its vLLM Deep Learning Container with vLLM 0.33.0 or later, or the Amazon Linux build server-sagemaker-cuda-v2.8.0 or later. Use a supported GPU real-time endpoint and OpenAI-compatible Completions or Chat Completions payloads. Enable prefix caching and container event reporting with SM_VLLM_KV_EVENTS_CONFIG, then set the variant routing strategy to KV_AWARE.

Compare random, prefix-aware and KV-aware routing with the same model, fleet size and prefix caching. Replay representative requests with the original document order, turn spacing and bursts. Start each run with fresh documents, rotate strategy order and repeat. Include a scale-out during a burst to see how long newly added instances take to warm up.

Measure client time to first token separately for first questions and follow-ups. Record the median and 95th percentile alongside completed requests per minute, endpoint overhead and the share of prompt tokens served from cache. A good median can hide a long wait for people opening fresh documents.

Agree the decision rule before the replay. For example, adopt KV-aware routing if it shortens peak follow-up waits enough to meet the team’s target while first questions stay within their own time limit and the fleet sustains the required completion rate. If prefix-aware routing meets those targets too, use the measured difference to decide whether changing the serving configuration is worthwhile.

Frequently asked questions

Will a single GPU instance benefit?

A single-model endpoint needs at least two instances for routing to make a difference. For an inference component, two copies suffice, even when they share one instance.

Can different questions reuse the same document?

Yes, if the prompts begin with the same token sequence and an available instance still holds it. Putting the question before the document can shorten the match to the words the questions have in common.

What happens when a matching instance is busy?

SageMaker weighs the length of the cached match against instance load. If all useful matches are too busy, it sends the request using load-aware routing. At launch, AWS provided no direct fallback metric.

← Back to the article library

Start with a conversation

Put your ideas into practice.

Tell us about your business and what you want to improve. We’ll help you find a sensible place to start.

Discuss Your Project