Shared KV Caching Needs a Workload Test Before a Cluster
Shared KV caching now has an AWS agent skill for evaluation and setup; I'd make workload economics and cross-server correctness the gates for adoption.
- Topic
- AI
- Reading time
- 8 min
- Length
- 1,768 words
- Published
- Nov 21, 2026
07:28 pm IST
In this article
- What is actually being cached?
- Does your workload need a shared cache?
- Evaluating a shared KV tier on an existing fleet
- Establish the workload before approving spend
- Use KVTrace instead of inventing a hit rate
- Make the decision gates explicit
- Rolling out the LMCache connector without losing correctness
- A successful connection is not a successful transfer
- Shared context still needs tenant isolation
AWS has added an agent skill to evaluate and set up distributed KV caching for self-hosted LLMs. It walks a coding agent through workload checks, cost estimation, deployment, and troubleshooting with Amazon ElastiCache. The point of the cache is to share attention state across GPU servers rather than have each server compute it again. Useful, potentially. But I'd treat the skill as a guided evaluation workflow, not an invitation to provision a cluster before checking whether the workload needs one.
The distributed KV caching skill works with Kiro, Claude Code, OpenAI Codex, and other coding agents that support Agent Skills. What I like is the order: check whether the cache fits, estimate the economics from the workload, ask for approval, and only then change infrastructure. For an agent with access to an inference fleet, I would want that sequence to be explicit rather than left to interpretation.
What is actually being cached?
Before an LLM generates a response, prefill computes key-value attention states for the input tokens. That work comes before the first output token. When someone returns to a conversation, the GPU handling the request may not have the conversation history cached, leaving it with substantial work to do before the user sees a response.
A distributed cache extends the GPU-local cache with a shared tier beside the fleet. Servers can reuse KV state across sessions, routing changes, and server failures, and that state can remain available for days. The upper-bound benefits are up to 40% lower self-hosted inference costs and up to 80% lower time to first token. Those are attractive numbers. I still wouldn't put either one into a capacity plan without measuring our workload first.
The distinction I keep coming back to is reused computation, not reused answers. The cache holds KV attention state; it does not hold a finished response. I'd look for recurring context when evaluating it: conversations that resume, coding agents returning to previous work, or document assistants processing the same shared material repeatedly.
For newsroom AI-assisted workflows, my first question would be whether an editor actually comes back to the same long context. A slow first response, on its own, wouldn't persuade me to add another tier. I'd want to see reusable context being recomputed because a request moved to another server or because enough time passed between turns.
Does your workload need a shared cache?
The skill checks simpler fixes before it proposes infrastructure. That seems like the right place to start. Turning prefix caching back on can help with back-to-back turns, and a GPU prefix-cache hit rate already above 90% with session affinity may mean there's no need for a shared cache. I'd exhaust that possibility before taking on the shared tier.
Short prompts would make me pause, too. Loading KV state can take longer than recomputing it. The prompt length at which loading becomes faster is the cutover point; that point, together with prompt repetition, determines whether the shared tier earns its cost. I'd evaluate short, mostly independent requests separately from long conversations that recur. One fleet-wide average isn't how I'd want to make that call.
Before getting into the cost model, I'd check the specific prerequisites:
- A coding agent that supports Agent Skills, plus GPU instances supporting EFA RDMA write, such as p5.
- LMCache 0.5.8rc1 or later, with either vLLM 0.11.1 or later or SGLang 0.5.13 or later.
- For cache setup, ElastiCache for Valkey 9.1 or later running on cache.i8ge.48xlarge nodes.
I wouldn't spend time building a savings model until those constraints were checked. This isn't an application-only optimization I can apply to a Node.js service that calls a hosted model. If I don't operate the inference servers, this particular deployment workflow isn't mine to apply, however appealing the latency numbers might look.
Evaluating a shared KV tier on an existing fleet
Establish the workload before approving spend
The skill begins with a read-only describe-instances call and counts EFA interfaces. Then it asks for what it cannot infer: the engine, model, tensor-parallel size, KV data type, server price, and prompt repetition. The evaluation also needs to account for replica count, routing, and the gaps between user turns. I'd want those details on hand before moving further.
I'd prepare the inputs as an engineering review rather than let the agent fill missing values with convenient assumptions. The behavior I'd document most carefully is users returning after the local cache is likely to have lost their context. That's the problem I want the shared tier to address. I wouldn't want it buried inside a general description of traffic.
Use KVTrace instead of inventing a hit rate
KVTrace records cache events from vLLM or SGLang, then replays them offline against candidate shared-cache sizes. The evaluation tool is available at no additional charge. The skill records on every GPU server over a representative window, such as a full business day. I'd rather start with that trace than invent the hit rate for a savings estimate.
The recorder writes neither prompt text nor token IDs. It does record block hashes and token counts, though, and those hashes come from token content. For sensitive prompts, the available flag is --anonymize-key-file. I'd make that requirement part of the trace collection review. “No plain text” wouldn't, by itself, settle the privacy question for me.
In the acceptance note, I'd keep the estimated latency benefit separate from the estimated reduction in spend. Freed GPU time only becomes dollar savings if fewer servers run or the same servers serve more traffic. If neither operational change is planned, I'd call the result available capacity. I wouldn't call it a smaller bill just because the GPU has less work to do.
Make the decision gates explicit
I'd keep a small application-side decision record alongside the evaluation, so the approval criteria are visible. This TypeScript is illustrative review logic, not an AWS configuration and not a replacement for KVTrace. The inputs stand for the workload estimate and the outputs captured during validation:
const cacheCostCovered =
estimatedAvoidedGpuCost > estimatedCacheCost;
const cacheLoadedOutputsMatch =
firstCacheLoadedOutput === secondCacheLoadedOutput;
const rolloutReview = {
cacheCostCovered,
cacheLoadedOutputsMatch,
readyForApproval:
cacheCostCovered && cacheLoadedOutputsMatch,
};
I'm assuming a controlled test here, with exact output equality chosen as the acceptance condition. What matters to me is keeping the checks separate. A good cost estimate cannot make incorrect output acceptable, and matching output doesn't establish a business case. Even after both checks pass, I'd require explicit human approval. That boolean would not be wired directly to provisioning.
Rolling out the LMCache connector without losing correctness
The skill adds the LMCache connector to an existing vLLM or SGLang engine, including vLLM workers under llm-d and Ray Serve. Routing and engine settings stay in place. Across the fleet, it aligns the KV ID mechanism, including the hash and seed, and sets an explicit KV data type. I'd pay close attention to that alignment during the rollout review.
Those settings need their own review, not just a glance at whether the connector started. A mismatch can leave each server writing state that the others cannot find. The more worrying case is a layout mismatch: hit counters can look healthy while answers are wrong. A dashboard full of hits wouldn't be enough for me to accept the deployment.
Before production traffic, the skill empties the local tiers and checks that two cache-loaded runs produce the same output. I'd make that a release gate. Emptying local state is a deliberate part of the test: I want to test the shared path, not get an apparently successful result because a warm local cache happened to serve the request.
Setup waits for approval of the node count, Availability Zone, and estimated price. It then creates the EFA security permissions and a Valkey cluster with a custom parameter group for caching eviction policies. LMCache receives a dedicated cache user, with the password stored in AWS Secrets Manager. The agent starts an LMCache server on each GPU server, tests a small object, and checks that repeated prompts load KV state over RDMA.
Next, I'd compare measured L2 share with the KVTrace prediction, as the skill does. If they disagree, I'd revisit the workload assumptions and configuration before expanding anything. This is where I'd apply the approval discipline discussed in centralizing MCP tool access for AWS DevOps Agent. Giving an agent access and permitting it to make a high-impact change are separate review decisions; I'd keep them separate here, too.
A successful connection is not a successful transfer
I'd keep the troubleshooting example in the runbook. An LMCache server can connect successfully and pass BLOB.RDMA_HELLO, yet fail on actual transfers while INFO largeobj shows an increasing count of rdma_write_errors. For that particular symptom pattern, the likely cause is a security group blocking EFA traffic between its own members. The connection check passing doesn't resolve that failure.
I'd make the distinction between connection checks and data-transfer checks explicit in deployment acceptance. It's the same testing principle I care about in fault tests that need more than healthy requests. A successful preliminary operation is worth checking, but I wouldn't let it stand in for the behavior the application actually depends on.
Shared context still needs tenant isolation
A shared KV cache also brings a timing concern. One tenant may be able to infer from response times whether another tenant submitted the same text. Cases that require isolation need separate caches. For tenants sharing a cache, their tenant ID is added to the KV hash. I'd want that distinction settled as part of the design, not left implicit.
I'd decide the tenant boundary before collecting the final economics. Approving a shared-cache design and leaving tenant separation for later gets the order wrong, I think. The proposed boundary for reuse has to be acceptable before its savings become interesting. I'd want to know what can share state before reviewing how much that sharing might save.
I'd also skip this work for a fleet whose local prefix caching already handles recurring context well. The same goes for prompts that rarely cross the point where loading is faster than recomputation. The agent skill makes evaluation and setup more accessible, but it doesn't remove either workload constraint. I'd rather stop there than provision a tier the workload doesn't need.
My next step would be the evaluation workflow, not an infrastructure change: collect a representative trace, write down a credible plan for using the recovered GPU capacity, and run the cross-server correctness checks. Those are the checks I'd need before giving the shared tier a clear job in the fleet. If they don't hold, I'd stop before provisioning; if they do, I'd take the evidence to the approval review.
Sources
Cut self-hosted LLM cost and latency with the distributed KV caching agent skill
This is the source this article is based on. Many articles on this blog are drafted with AI and checked against their source automatically; the editorial policy explains how, and how to report a mistake.
Frequently asked
Can I use the skill with Claude Code or OpenAI Codex?
Yes. It works with Kiro, Claude Code, OpenAI Codex, and other coding agents that support Agent Skills. The inference fleet must separately meet the GPU, engine, LMCache, and ElastiCache prerequisites.
Does KVTrace store prompts, and does evaluation cost extra?
KVTrace is available at no additional charge. Its recorder stores block hashes and token counts, not prompt text or token IDs. Because the hashes derive from token content, sensitive workloads should use --anonymize-key-file.
Should I add a shared cache if prefix caching already works?
Not automatically. A local GPU prefix-cache hit rate above 90% with session affinity may mean a shared tier is unnecessary. I'd evaluate remaining cold-prefill work and cache economics before adding infrastructure.
Weekly newsletter
Liked this? Get the next one by email
One short email a week with new articles on React, Node.js, TypeScript and AI engineering. No spam. Unsubscribe in one click.
Further reading
Related tutorials from ByteMuni, my developer publication.
- AI AgentsMeta Muse blocks expose the limits of agent permissionsMeta Muse access restrictions put platform consent ahead of customer authorization; Walmart's planned profiles show how agent identity and purchase controls could work.
- AI Coding ToolsFable 5.2 lowers API prices but still needs human oversightAnthropic’s Fable 5.2 lowers API prices and improves coding scores; Bedrock users need to check retention, effort settings, and refusal handling before migrating.
- AWS & CloudAWS Lambda Web Functions: A Developer Guide to Lambda Without HandlersAWS Lambda Web Functions let your Node.js server listen on a port and serve up to 128 requests per warm environment, billed on active CPU. This developer guide covers the new programming model, the launch limits, deploys and canaries, pricing checked against AWS's own examples, and the gotchas early adopters have already found.