Background: Cache Bottlenecks Faced by Self-Hosted LLMs
There is an increasing trend of companies self-hosting large language models (LLMs) on GPU clusters to control costs, accuracy, and latency. However, when each GPU server only has an independent small prefix cache, duplicate prefill operations occur every time conversation history accumulates, leading to a surge in costs and latency. According to the AWS blog, in workloads that accumulate hundreds of thousands of tokens of case history, resuming a conversation after lunch can take several minutes to generate the first token. This is because the GPU server receiving the request does not have the key-value (KV) attention state for that history, necessitating a re-execution of the prefill for all tokens. This bottleneck is common across long-context and multi-turn workloads, including coding agents, agentic AI assistants, and document Q&A systems.
Solution: Distributed KV Caching and Agent Toolkit Skill
AWS addresses this issue with a distributed KV cache layer based on Amazon ElastiCache for Valkey. By placing a shared cache tier next to the GPU local cache, it allows KV state to be reused across any server, even during session changes or failures over several days. The newly announced distributed KV caching skill of the Agent Toolkit for AWS automates the evaluation, construction, and operation of this architecture with just a few natural language prompts within coding agents. Supported agents include all tools following the Agent Skills protocol, such as Kiro, Claude Code, and OpenAI Codex.
"Announcing distributed KV caching for self-hosted LLMs with Amazon ElastiCache" dives into the technical details and the performance benchmarks.
The four conversation flows guided by the skill are as follows:
1. Slow First Token Diagnosis — Identify causes of cold prefill and prioritize review of non-infrastructure alternatives (reactivating prefix cache, session affinity) 2. Cache Size and Cost Estimation — Estimate savings using KVTrace simulation based on internal traffic 3. Cache Cluster Construction — Inject LMCache connector into vLLM/SGLang, unify KV ID mechanisms and data types 4. Transmission Failure Recovery — Troubleshoot operational issues such as layout mismatches and key mismatches
Technical Architecture and Prerequisites
To apply the distributed KV caching skill, the following runtime environment is required.
| Component | Minimum Version / Specification | Notes |
|---|---|---|
| GPU Instance | p5 (EFA RDMA write support) | Elastic Fabric Adapter required |
| Inference Engine | vLLM 0.11.1+ or SGLang 0.5.13+ | Includes llm-d, Ray Serve sub-workers |
| LMCache Connector | 0.5.8rc1+ | Plugin for vLLM/SGLang engine |
| Cache Cluster | ElastiCache for Valkey 9.1+, cache.i8ge.48xlarge node | During production deployment |
| Coding Agent | Supports Agent Skills such as Kiro, Claude Code, OpenAI Codex | Entity executing the skill |
The skill scans the GPU fleet with a read-only `describe-instances` call to count the number of EFA interfaces and asks the user for engine, model, tensor parallel (TP) size, KV data type, server pricing, and prompt repetition frequency. It immediately halts and explains the reason if conditions are not met.
Actual Application Flow: From Diagnosis to Construction
Flow 1: Legal Assistant 64K Context Diagnosis
User Prompt: "My vLLM fleet is serving a legal assistant with a 64K token context. It takes 13 seconds to get to the first token in resumed conversations. The GPU recalculates the entire conversation history every turn. How do I fix this?"
The agent identifies cold prefill as the cause and presents three practical considerations.
- Prioritize checking non-infrastructure alternatives: If the prefix cache is off, reactivate it; if the GPU prefix cache hit rate is over 90% under session affinity, shared KV cache is unnecessary
- Tenant Isolation: When using shared cache, it is possible to infer whether the same text is sent to other tenants based on response time → cases requiring isolation need separate cache, shared tenants should add their own ID to the KV hash
- Prohibit estimation; base on actual measurements: Scale estimation should be based only on actual parameters such as model, TP size, KV data type, number of replicas, routing, and inter-turn latency
Flow 2: Scaling Estimation for 8 p5 Instances RAG Assistant
Example Fleet: 8 p5 instances, 64,000 token prompt, multi-turn RAG assistant. The agent queries the AWS pricing table for GPU and cache node prices and derives prefill speed and KV size from benchmarks, recommending 2 cache.i8ge.48xlarge nodes. Since the user did not provide the cache hit rate (the ratio of tokens being recalculated that the cache serves), the agent presented scenario-based estimates and recommended securing actual hit rates through KVTrace execution.
| Cost Reduction 40% | |
| TTFT Reduction 80% | |
| 2 Cache Nodes |
Quantitative Effect Verification through KVTrace
KVTrace records KV cache events in vLLM or SGLang and then replays offline by candidate cache size to calculate hit rates. Token IDs or prompt texts are never recorded, only block hashes and token counts are stored. Since block hashes originate from token content, if the prompt is sensitive, it can be anonymized using the `--anonymize-key-file` option. The recorder runs on all GPU servers and can be used without additional charges.
The skill assesses whether the savings cover the cache costs based on KVTrace results, and if not covered, it halts the construction. All figures specify sources (AWS pricing table, benchmarks, internal traces).
Considerations and Best Practices for Deployment
The skill enforces the following validation steps before introducing production traffic.
- Empty local tier and execute cache load twice for identity verification — Prevent cases where the hit counter appears normal due to layout mismatches but generates incorrect answers
- Explicit approval required for high-impact operations (resource creation, modification, deletion)
- Unify KV ID mechanisms (hash, seed) and KV data types across the fleet — Prevent issues where other servers cannot find KV states written due to key mismatches
- Preserve routing and engine settings — Inject the connector without changing the existing serving stack (llm-d, Ray Serve, etc.)
These guardrails are designed to minimize operational risks while safely realizing the cost and latency benefits of distributed KV caching.