01 article

Shared KV Cache Stops Your GPU From Recomputing 95% of the Prompt

Over 95% of the tokens in an agent turn were already processed once, so the GPU burns minutes rebuilding KV states it computed earlier. AWS's distributed KV caching on ElastiCache for Valkey, plus Valkey 9.2's new Path Hash type, turns that recomputed work into a shared cache tier.

Shared KV Cache Stops Your GPU From Recomputing 95% of the Prompt

Shared KV Cache Stops Your GPU From Recomputing 95% of the Prompt

Every turn of a coding agent resends the whole conversation: system prompt, tool definitions, every prior message. The model needs all of it again, but the math is already done. The AWS launch post cites traces from SemiAnalysis and TraceLab showing that over 95% of prompt tokens are part of a prefix the engine has already processed. The GPU recomputes attention states it computed minutes ago, and on long agent sessions that recompute runs to minutes per request. On November 18, 2026 AWS made a managed answer generally available with distributed KV caching on ElastiCache for Valkey, and Valkey shipped 9.2 the next day with a new data type for exactly this lookup.

Prefill is the bill, decode is the rounding error

An inference request has two phases. Prefill reads the entire prompt and computes key-value attention states for every token. Decode then generates tokens one at a time, reusing those states. Time to first token is basically prefill latency, and prefill scales badly: in AWS's tests on B300 GPUs, a 32K-token prompt took seconds, a 100K-token prompt took tens of seconds, and past 250K tokens you wait minutes.

Engines already exploit this. vLLM and SGLang split the KV cache into fixed-size blocks identified by a hash of their content plus everything before them. A request sharing a prefix with an earlier one reuses the matching blocks and computes only the uncached suffix. The TripleKV paper (arXiv 2611.25112) measured 84.6 to 99.5% of input tokens hitting the prefix cache in agentic workloads. That stat hides four words: when capacity is sufficient.

The local cache dies with the box

Capacity is the whole problem. Under real concurrency the combined KV working set of a fleet reaches hundreds of gigabytes, far past GPU memory, and engines spill to host DRAM and local SSD. That hierarchy leaks in three places. It dies with the process, so every deploy flushes it. It does not share between servers, so a load balancer that sends the next turn to a different replica pays the full recompute. And it is sized for one box, not the workload.

AWS's example is a legal assistant on p5 instances where users returning to a thread waited 13 seconds for the first token. The root cause turned out to be a disabled prefix-caching flag, a reminder to check your config before buying hardware. But the shape of the failure is the point: user resumes, cache cold, GPU rebuilds everything.

What AWS actually shipped

Distributed KV caching adds a fourth tier: a shared cache beside the GPU fleet. It runs on dedicated cache.i8ge.48xlarge nodes in the same availability zone, attached over RDMA via Elastic Fabric Adapter, storing KV blocks in DRAM plus NVMe using Valkey's new large-object support. Any server can pull state written by any other, in milliseconds, and the state survives days across sessions, routing changes, and host failures. AWS claims up to 40% lower inference cost and up to 80% lower time to first token. Treat both as ceilings that depend on hit rate.

You attach it through the open-source LMCache connector, a configuration change with no code changes. The prerequisites are specific: vLLM 0.11.1 or later, or SGLang 0.5.13 or later, LMCache 0.5.8rc1 or newer, GPU instances with EFA RDMA-write support, and Valkey 9.1 or later on the cache nodes. Open-weight, fine-tuned, and custom models all qualify, and the design is agnostic to attention architecture, so sparse and hybrid attention models can use it too.

Path Hash is the quietly interesting release

Finding reusable KV state is a prefix-matching problem: the longest path matching the incoming prompt, plus where that path's blocks live. Rolling this yourself means custom routing logic keyed on block hashes. Valkey 9.2 (November 19) ships Path Hash, a native data type where one command returns the longest matching prefix and the storage locations of the cached results. The heavy KV blocks stay in GPU or host memory while Valkey acts as a lightweight index. Prefix matching over hierarchical paths is a database primitive now, not an inference-side hack. The rest of 9.2 (forkless snapshots, stream compression, B+ tree sorted sets) targets ordinary operating costs.

Measure before you provision

Whether a shared tier pays depends on your model, prompt mix, and traffic, so AWS shipped a measuring instrument before asking anyone to buy cache nodes. KVTrace, open source in the amazon-elasticache-samples repo, records KV-cache events from vLLM or SGLang and replays them offline against candidate cache sizes. The recorder stores block hashes and token counts rather than prompt text, which matters in regulated domains. It costs nothing, and the skill stops if estimated savings do not cover the cache's price.

The coding-agent skill is the second story

On November 20 AWS published a distributed KV caching skill in the Agent Toolkit for AWS, usable from Kiro, Claude Code, OpenAI Codex, and anything else that speaks Agent Skills. It runs a fit check first: a read-only describe-instances call to inventory the GPU fleet and count EFA interfaces, then questions about model, engine, tensor-parallel size, KV data type, server price, and how often prompts repeat. Then it estimates with KVTrace, provisions the cluster with security groups and Secrets Manager entries, verifies connectivity with a test prompt, and handles troubleshooting.

The fit-check-first ordering is the part worth stealing, and so is a tool that can talk you out of buying the thing. The workloads that benefit (long contexts, heavy prefix repetition, multi-replica fleets) are narrow enough that a guided setup should be able to say no.

When to skip it

AWS itself notes that for short prompts, fetching cached state can cost more than recomputing it. The same-availability-zone requirement limits consolidation. The 40% and 80% figures are AWS's own. And if you run no GPUs, the hosted APIs sell the same idea: Anthropic's Message Threads cut median time to first token about 35% on long sessions without changing token billing, and OpenAI added 12-hour prompt caching around November 17 at 2.5x the write price. The self-hosted version at least moves a real cost line, because the recomputed GPU work is money you are already burning.

The Monday checklist

  • Pull the prefix-cache hit rate from your engine's metrics. If it is low on long sessions, find out why: routing, deploys, or capacity.
  • Count what share of the tokens in a typical turn were already sent earlier. If it is nowhere near 90%, you do not have this problem.
  • Check your load balancer. Round-robin across replicas quietly destroys per-server prefix caches, and sticky sessions are a free fix.
  • Replay a day of traffic through KVTrace before provisioning, and read the projected savings against the cache bill, not against your hopes.
  • If you use a hosted API, confirm the cache is actually hit (cached-input tokens in the usage object). A miss is invisible in the response.

Prefill is compute, but the KV state it produces is data. Treat that data as cacheable, with a shared tier and a hit-rate metric you actually watch, and the question stops being why the GPU is slow and becomes why the cache is cold. Now there is a database primitive for it.

Comments