When Caching Is Slower Than Computing: The Hidden Costs of LLM Inference
Caching is a standard optimization in LLM inference, but on a large-scale MoE inference cluster, enabling a shared KV cache left median latency unchanged while p99 latency jumped from 3.96s to 17.3s. This article explains why reading a cache can be more expensive than recomputing, analyzes the system architecture behind the regression, and offers practical fixes: asynchronous writes, local-first caching, explicit cost criteria, and p99-focused monitoring.
1. A Counterintuitive Phenomenon
In LLM inference services, caching is treated as a default performance optimization: store previously computed intermediate results and reuse them for similar requests, avoiding large amounts of redundant computation. This principle appears in virtually every performance optimization textbook.
However, on a very large Mixture-of-Experts (MoE) inference cluster, engineers encountered a phenomenon that defied this intuition. To accelerate long-context processing, the team introduced a shared cache layer to store attention intermediate data (KV data) computed from historical requests. The expected logic was simple: on a cache hit, reading stored data should be far faster than recomputing attention over an entire context.
The actual result: after enabling the cache, the system’s median latency barely changed, but the slowest 1% of requests (p99 latency) jumped from 3.96 seconds to 17.3 seconds—more than a 4x regression. The cache feature had to be rolled back entirely.
This case reveals a frequently underestimated fact: reading from a cache has a cost of its own. When the cache read path is highly contended and storage bandwidth is limited, “reading the cache” can be slower than “recomputing from scratch.”
2. System Background: Understand the Hardware First
To understand this performance problem, you need to know three key characteristics of this type of inference system.
1. Storage Pressure from Attention Intermediate Data
Modern large models commonly use attention mechanisms that compress each token’s key-value information into low-rank vectors. This design dramatically reduces the amount of intermediate data to store: regardless of how many attention heads the model has, the data size per token is fixed. At FP8 precision, every 256 tokens are packed into one “block” of roughly 12 MB, averaging only tens of KB per token.
This means storing intermediate data is not inherently “large”—the problem is the access pattern. Under high-concurrency inference, read and write requests for this data become extremely dense.
2. Parallelizing the Prefill Stage
Long-context processing is one of the most compute-intensive stages of inference. A common approach is prefill context parallelism: split a long text into segments and distribute them across multiple GPUs within a node for simultaneous processing. After each GPU finishes its assigned shard, it must synchronize results to all other GPUs over the network, so that every GPU has the complete context.
3. A Tightly Synchronized “Gear” Structure
Under this architecture, the 8 GPUs (8 ranks) on a node behave like a set of interlocking gears: every step requires mutual communication and synchronization. If a single rank slows down, the other seven must stop and wait. This is the core premise of all the performance analysis that follows—one slow point slows the whole system.
3. Cache Architecture: A Two-Tier Design and Its Bottleneck
The system uses a typical two-tier cache structure:
- L1 (local cache): resides in each inference engine’s local memory. Fast to access, but limited in capacity and visible only to its own engine.
- L2 (shared cache): deployed on a separate key-value database. Large capacity, shared by all inference engine instances—essentially a “public library.”
The problem lies precisely in the L2 tier.
An analogy: imagine a chain of bubble tea shops where each store keeps its own ledger (L1), but for headquarters to audit centrally, every store’s transactions must be written into a single master ledger (L2)—maintained by one accountant. When business is brisk, eight stores try to write at once and all end up queuing at the accountant’s desk.
Mapped back to the inference system: the node’s 8 ranks work in parallel, and after each rank finishes its shard, it writes its generated intermediate data blocks into the same shared storage. Meanwhile, other requests may be reading historical data from that same storage. The shared storage’s bandwidth, connection count, and I/O capacity become a common bottleneck for the entire node.
4. Why p99 Degraded While the Median Stayed Flat
This is the most instructive part of the case—and a blind spot for many engineers doing performance analysis.
Median latency unchanged means: most requests never touch the L2 cache path (cache misses), or their cache-hit gains are exactly canceled out by write overhead. These requests behave almost identically to the no-cache case.
p99 latency spiking means: some requests’ execution paths were significantly slowed by the caching mechanism. The likely causal chain includes:
- Write amplification: every parallel rank writes to the cache, so 8 ranks’ write requests flood the shared storage at the same moment, creating burst I/O peaks.
- Critical path contamination: if cache reads/writes are placed on the synchronous critical path—i.e., “must finish writing the cache before the next step”—then any jitter in shared storage is directly amplified into end-to-end latency.
- Queuing and cascading amplification: because the 8 ranks are tightly synchronized, if any single rank’s cache I/O is slow, the entire node’s prefill stage waits for it. Behind one slow request are 7 collateral ranks, systematically amplifying the long tail.
- Contention and hot spots: popular contexts (such as frequently repeated system prompts) concentrate reads on the same set of cache keys, while L2 network and storage bandwidth allocation does not automatically optimize for hot spots.
In short, the original design put cache I/O in the wrong place: it was neither off the critical path nor buffered or smoothed against concurrent writes.
5. Optimization: Turning a Bottleneck into Real Speedup
To rescue this caching system, the core principle is: move cache reads and writes off the critical path, and make I/O cost measurable and controllable.
1. Asynchrony: Writes Must Not Block Computation
Cache writes should be a best-effort background task. Return results downstream immediately after prefill completes, and let an asynchronous thread handle writing out the intermediate data blocks:
# Pseudocode: asynchronous cache writedef prefill(request):kv_blocks = compute_attention(request.context) # critical pathschedule_async(lambda: kv_store.put(request.hash, kv_blocks)) # non-critical pathreturn kv_blocks # return without waiting for the write to complete
2. Local First, Shared as Fallback
The responsibilities of L1 and L2 need to be re-divided: hot data lands locally first; writes to L2 use merging, batching, and rate limiting to prevent 8 ranks’ simultaneous burst writes from overwhelming shared storage. A write queue can smooth the peaks:
Write policy: aggregate locally per rank → batch flush to L2 on timer/size threshold → drop if queue exceeds watermark (fall back to recomputation)
3. Explicit Criteria for Whether Caching Is Worthwhile
Not all data is worth caching. The decision should be an explicit formula: reuse probability × recomputation cost > write cost + read cost + storage cost. For contexts with low reuse rates, skipping the cache entirely is often the better choice.
4. Monitor the Tail, Not the Average
One of the biggest lessons of this case: looking only at average or median latency will never reveal the problem. You need tiered p95/p99 monitoring, and separate instrumentation for “cache hit rate” and “cache I/O time as a share of end-to-end latency,” to locate where the cost is actually spent.
6. Final Thoughts
What this case overturns is not “caching is useful,” but the implicit assumption that “caching is free.” In distributed systems, every access to a shared resource has a cost—bandwidth, connections, locks, queuing, synchronization waits—any of which can become an amplifier of tail latency.
The takeaways for engineers can be summarized in three statements:
- Price cache benefits by reuse probability, not by intuition;
- Shared storage is a global bottleneck—writes must be asynchronous, batched, and degradable;
- Performance analysis must look at p99; tightly synchronized parallel architectures amplify any single-point jitter into collective waiting.
When the cache is slower than computation, the problem usually isn’t the cache itself—it’s that we never seriously accounted for the cost of “reading.”
