When Cache Reads Cost More Than Computation: The Hidden Cost of Caching in LLM Inference
Caching is usually expected to accelerate large language model inference, but shared cache reads can become a major source of latency. This article examines why an MoE inference system saw p99 latency rise from 3.96 seconds to 17.3 seconds after enabling caching, and presents cost-aware cache decisions, asynchronous reads, batching, fast fallback, write-path optimization, and the metrics needed to control tail latency.
Introduction: When a Common Assumption Breaks
In production systems for large language model inference, “caching makes things faster” is often treated as a given. However, one team experienced the opposite while serving an extremely large mixture-of-experts (MoE) model.
The model was deployed on a node with eight high-performance GPUs. To accelerate long-context processing, the engineering team introduced a shared cache for previously computed attention intermediates. The expectation was that similar requests could reuse these results and avoid repeated computation.
The outcome was very different. After caching was enabled, median latency barely changed, while p99 latency increased from 3.96 seconds to 17.3 seconds. Under production pressure, the team eventually rolled back the feature.
The central lesson is simple: reading from a cache has a cost, and that cost is often seriously underestimated. This article follows the troubleshooting process, explains why the cache became a bottleneck, and outlines a systematic approach to fixing it.
1. Understanding the System: How the Model Uses GPU Resources
1.1 Cache Efficiency from Low-Rank Attention Compression
The model uses a low-rank compressed attention mechanism. The key-value information for each token is compressed into a shared low-rank vector, so the amount of intermediate data stored per token remains fixed and small regardless of the number of attention heads.
In this scenario, low-precision storage is used to pack every 256 tokens into a data block of approximately 12.4 MB. That works out to roughly 48.4 KB per token.
This gives the cache excellent space efficiency and makes it theoretically well suited for reuse across requests. It was also the main reason the team initially had confidence in the shared-cache design.
1.2 Parallel Long-Context Processing and Synchronization Overhead
Long-context prefill is computationally expensive, so the system uses context parallelism. A long input is divided into multiple partitions and distributed across several GPUs for simultaneous processing. Once processing is complete, the GPUs exchange results over the network so that every GPU has the full context.
This introduces an important constraint: the eight ranks on the same node operate like interlocking gears. They must synchronize at every step. If one rank slows down, the other seven must wait.
Under this tightly coupled execution model, even a local tail-latency spike can become a global latency increase.
1.3 Two-Level Cache Architecture
The cache system has two layers:
- L1, or local cache: Stored in the local memory of each inference instance. It is fast but limited in capacity and is available only to that instance.
- L2, or shared cache: Stored in a general-purpose distributed key-value store. It has greater capacity and is shared by all inference engine instances, much like a public library.
The main problem was in L2.
2. Locating the Bottleneck: One Accountant Serving Eight Stores
A useful analogy is a chain of eight beverage stores. Each store maintains its own local records in L1, but headquarters requires all records to be written to and read from one shared ledger in L2. Unfortunately, that ledger has only one accountant.
When business is light, the arrangement works. When all eight stores send large numbers of read and write requests at the same time, every store ends up waiting in line at the accountant’s desk.
Technically, the L2 layer exposed three main problems:
Serialized access bottlenecks: Multiple inference instances concentrated their reads and writes on the shared key-value store. Network round trips, serialization and deserialization, connection queuing, and related overhead accumulated. In some cases, a cache read took nearly as long as—or even longer than—recomputing the data.
Synchronization amplified tail latency: Because the eight ranks advanced in lockstep, a single rank experiencing a long L2 read—for example, because of network jitter or storage-side queuing—could delay the entire step. p99 latency is particularly sensitive to these occasional slow paths, producing the familiar pattern of stable median latency but sharply degraded p99 latency.
Cache-hit decisions ignored cost: The system assumed that a cache hit was always beneficial. In practice, it should compare the cost of reading the cache with the cost of recomputation. When cache blocks are small and recomputation is fast, fetching data over the network can be slower than calculating it locally. Without this comparison, the cache changes from an accelerator into a liability.
3. Redesigning the System: Making Cache Reads Faster Than Recomputation
3.1 Build a Cost Model: A Hit Does Not Guarantee a Benefit
The first step is to introduce an explicit cost comparison. For every potential cache hit, estimate the cost of both paths:
# Pseudocode: cost-aware cache-hit decisiondef should_use_cache(block, cache_latency_est, recompute_cost_est):# cache_latency_est: estimated network RTT, deserialization, and queuing time# recompute_cost_est: estimated local compute time for this blockif cache_latency_est < recompute_cost_est * SAFETY_MARGIN:return fetch_from_cache(block)else:return recompute_locally(block)
SAFETY_MARGIN is a conservative factor, such as 0.8, that accounts for errors in latency estimation. The system should use the cache only when the expected benefit is sufficiently large. Otherwise, local recomputation is preferable.
3.2 Make the Read Path Asynchronous and Parallel
L2 reads should be removed from the critical synchronous path wherever possible:
- Prefetch: Once the required cache blocks are known, start asynchronous reads in advance so network transfers overlap with ongoing computation.
- Batch reads: Combine multiple small requests into a single batch request to spread network round-trip time and other fixed request-processing costs across more data.
- Tiered fallback: If an L2 read does not return before a timeout, immediately fall back to local recomputation. This prevents indefinite waiting from creating additional tail latency.
3.3 Reduce Pressure on the Write Path
Writes to shared storage can also harm read performance. Potential strategies include:
- Write only blocks with high reuse value, using historical hit rates for admission control.
- Make writes fully asynchronous and batch them before persistence.
- Shard hot keys to prevent a single partition from becoming the “one accountant” serving all requests.
3.4 Monitor the Right Metrics
The issue was discovered because the team monitored p99 rather than focusing only on averages and medians.
For strongly synchronized parallel inference systems, monitoring should include at least:
- Cache read and write latency at p50, p99, and p999
- Cache hit rate
- Hit benefit, calculated as saved compute time minus cache-read time
- Step-level stall duration caused by cache waits
4. Key Takeaways
This case offers three lessons for engineers optimizing inference systems.
First, caching trades space for time, but whether the trade is worthwhile depends on the real cost of the read and write paths. When the cache is accessed over a network, fixed overhead can consume the entire benefit.
Second, in a strongly synchronized parallel architecture, tail latency becomes global latency. Improving p99 can have a greater effect on the real user experience than improving the average.
Third, cache policies need both cost awareness and fast fallback. A system that can calculate whether it is better to read or recompute is the system that can fully benefit from the capacity advantages of a shared cache.
Caching is not free. But once its costs are measured correctly, it can still deliver substantial value.
