LLM Inference Caching: Why Cache Hits Can Increase Tail Latency

    Caching intermediate attention states in LLM inference sounds like a straightforward way to avoid recomputation, but in distributed long-context serving it can shift cost into cache lookup, transfer, deserialization, memory copies, and cross-GPU synchronization. This article examines a tail-latency regression in an eight-GPU MoE inference system, explains why p99 latency can rise even when median latency looks stable, and outlines practical safeguards such as read-cost thresholds, hierarchical caching, block aggregation, isolation, and rollback controls.

    In LLM inference systems, “cache the computation result and reuse it next time” sounds like an almost naturally correct optimization. This is especially true for long-text requests: the model must repeatedly process a large amount of historical context, and if it can reuse already generated attention intermediate states, there is an opportunity to reduce repeated computation, lower response time, and reduce GPU load.

    In engineering practice, however, the result can be counterintuitive. After caching is enabled, average or median latency may not change much, while the slowest subset of requests becomes noticeably slower. A mixed-expert inference system running on an eight-GPU node encountered exactly this problem. With caching enabled, median performance remained basically stable, but tail latency—the p99 latency—rose from about 4 seconds to more than 17 seconds, and the cache feature ultimately had to be temporarily disabled.

    The problem is not that “the idea of caching is wrong.” The problem is that the system accounted only for the compute cost saved after a cache hit, without fully accounting for the cost of reading the cache itself. For distributed LLM inference, cache access may involve memory copies, data decompression, network transfer, remote storage queueing, cross-GPU synchronization, and resource contention among requests. Once these costs land on the critical path, the cache can turn from an accelerator into a new bottleneck.

    Why Long-Context Inference Relies Heavily on Caching

    LLM inference can usually be split into two phases.

    The first phase is prefilling, which processes the entire context of the user input. The model reads these tokens layer by layer and computes attention-related intermediate states. The second phase is token-by-token generation, where each step generates only one or a few new tokens, but each step needs to access the key-value states corresponding to the prior context.

    Without caching, the model may need to recompute the attention states of historical context when generating new tokens. The longer the context, the higher the proportion of repeated work. Engineering systems therefore usually save these intermediate results and read them directly during later generation. For requests with long input text, this kind of cache can significantly reduce repeated computation.

    But the benefit of caching depends on three conditions:

    1. Whether subsequent requests will actually reuse existing content;
    2. Whether cached data can be retrieved in time when needed;
    3. Whether the cost of retrieving the data is lower than the cost of recomputing it.

    If the hit rate is not high, cache space and access overhead are hard to amortize. If the cache is remote, network transfer and server-side queueing must also be considered. When a request must read a large amount of cached data before it can continue computation, cache reads go directly onto the end-to-end latency critical path.

    Attention States Are Not Just “Stored”

    Modern LLMs often use low-rank or compressed attention structures to reduce the intermediate state that must be saved for each token. Compared with traditional multi-head attention, these designs can reduce cache capacity and make long-context inference more feasible.

    In some implementations, cache data is stored in blocks based on a fixed number of tokens. Suppose a cache block contains 256 tokens. With a low-precision format, each block may be more than ten megabytes, and the average per token may still reach tens of KB. For contexts of tens of thousands of tokens or more, the amount of data a single request needs to read is not small.

    More importantly, cache data usually does not enter the compute unit at zero cost directly from the storage medium. It may go through multiple stages:

    • Compute the cache key based on request content;
    • Query cache metadata;
    • Read data from local memory or a remote service;
    • Process the network protocol;
    • Complete deserialization, decompression, or format conversion;
    • Copy data into a memory region suitable for computation;
    • Wait for synchronization across multiple GPUs;
    • Finally hand the data to the attention computation module.

    Queueing at any of these steps delays subsequent computation. A cache hit does not mean the request immediately gets a result. What matters is the full time from initiating the read to the data becoming usable by computation.

    Synchronization in Distributed Inference Amplifies Local Problems

    Long-text prefilling often uses context parallelism: an input sequence is split across multiple GPUs, each GPU processes a portion, and results are exchanged over a high-speed interconnect. This can expand the supported context length and reduce per-GPU memory pressure.

    But context parallelism has a clear characteristic: multiple GPUs often need to synchronize at certain stages. If one GPU reads its cache slowly, the other GPUs may have to wait even if they have finished their own work.

    This process can be abstracted as:

    1. Total latency ≈ max(each GPU's compute time + each GPU's cache access time)
    2. + cross-GPU synchronization time

    The key here is not the average time across all GPUs, but the time of the slowest GPU. If seven of eight GPUs finish reading within 100 milliseconds, but one GPU takes 600 milliseconds because of remote cache queueing, the entire parallel stage will usually still need close to 600 milliseconds before it can continue.

    This is also why cache problems often first appear as p99 latency degradation. Most requests may not encounter severe queueing and keep normal latency. But once a small number of requests hit hot keys, background reclamation, network jitter, or an overloaded shard, they slow down the entire synchronization group.

    Hierarchical Cache Design: Fast Near, Large Far

    A common cache architecture can be divided into two layers.

    The first layer is the local cache on the node where the inference process runs, usually using host memory or high-speed memory near the device. Its advantages are a short access path and low latency. Its disadvantages are limited capacity and the fact that different inference instances may not share it.

    The second layer is a remote shared cache, which has larger capacity and can be accessed by multiple inference instances. It is suitable for storing hot context, data reused across instances, and content that cannot fit in local cache. But its access path is longer, and concurrent queueing is more likely.

    Ideally, requests should access caches in the following order:

    1. Local cache hit
    2. ↓ miss
    3. Node-level shared cache
    4. ↓ miss
    5. Remote cache or recomputation

    But this strategy cannot be simplified to “a remote hit is always worthwhile.” If remote read time is already close to or even greater than recomputation time, continuing to read the cache will instead add latency. A more reasonable judgment is to compare:

    1. Read cost = lookup + queueing + network transfer + decoding + memory copy + synchronization wait
    2. Compute cost = GPU computation and synchronization required for recomputation

    Only when read cost is significantly lower than compute cost does a cache hit truly make sense.

    Why Remote Shared Caches Easily Become Bottlenecks

    A shared cache is usually used by multiple inference instances. As business scale grows, access volume may show bursty growth: multiple requests hit the same prefix at the same time, or multiple parallel work units read different data blocks at the same time.

    In this situation, the remote cache service may encounter the following problems.

    1. Single-shard hotspots

    If cache keys are unevenly distributed, a large number of requests may concentrate on a few shards. Even if the overall cache cluster still has idle resources, the hot shard will queue, causing local high latency.

    2. Read/write interference

    The cache must handle not only reads but also writes, expiration deletion, space reclamation, and metadata updates. When a large amount of new data is written at the same time, read requests may be affected.

    3. Too many small requests

    Storing cache data in blocks does not mean access is necessarily efficient. If a request needs to read many small blocks, it creates more network round trips, protocol processing, and scheduling overhead. Even when the total data volume is not large, too many small requests can cause noticeable latency.

    4. Concurrency amplification

    One user request may correspond to multiple concurrent cache reads, and one parallel inference batch may contain multiple user requests. The final number of requests reaching the shared cache is far higher than the apparent number of user requests.

    5. Eviction-induced jitter

    When cache capacity is insufficient, the system needs to evict old data. If eviction, write, and read policies are not coordinated well, data that was just written may be quickly evicted, then recomputed and written back again, creating ineffective churn.

    Optimizing a Cache Requires More Than Hit Rate

    Hit rate is an important metric for a cache system, but it is not the only metric. Even if a cache achieves a high hit rate, if hit requests have high read latency, the overall benefit may still be negative.

    It is recommended to observe at least the following metrics together:

    • L1 and L2 hit rates;
    • Average, p95, and p99 cache read latency;
    • Data volume read per request;
    • Number of cache blocks involved per request;
    • Cache server-side queueing time;
    • Network transfer time;
    • Deserialization and memory copy time;
    • Compute time actually saved after a cache hit;
    • Cross-GPU wait time caused by cache reads;
    • Load distribution across shards and instances.

    You can further define net cache benefit:

    1. Net cache benefit = avoided compute time - total cache access time

    If net cache benefit is less than zero, you should consider skipping the cache read and recomputing directly, or reading only the most valuable portion.

    More Robust Engineering Approaches

    1. Set a read-cost threshold

    The system can estimate read cost based on cache block size, historical read latency, and current queueing conditions. When estimated read time exceeds recomputation cost, it should take the compute path directly.

    This is not cache invalidation; it gives the cache the ability to be used conditionally.

    2. Prioritize local cache

    Local cache should store the hottest data that is most likely to be reused by recent requests. Remote cache should serve as a capacity supplement, not the default mandatory path for all requests.

    At the same time, local cache must not be allowed to expand excessively, or it may squeeze memory needed by inference processes, communication buffers, and the operating system.

    3. Aggregate cache blocks reasonably

    Cache blocks that are too fine-grained increase request count and metadata overhead, while cache blocks that are too large may cause useless reads. Block size should balance context repetition patterns, network bandwidth, GPU memory capacity, and access concurrency.

    4. Avoid random remote reads inside synchronization groups

    In multi-GPU parallel scenarios, cache metadata decisions can be completed first, followed by batched reads of contiguous data, minimizing random access during the synchronization stage. When necessary, some cache reads can also be overlapped with other computation to reduce cache blocking on the critical path.

    5. Replicate or tier hot content

    For public prefixes with extremely high access frequency, replicas can be kept on multiple nodes to reduce the risk of all requests concentrating on the same remote shard. However, replication increases capacity consumption and consistency maintenance cost, so it is suitable for stable, long-term hot data.

    6. Use rate limiting and isolation mechanisms

    Cache read traffic should not hit shared services without limit. Concurrency limits can be set by tenant, model, node, or request priority, and background prefetching, eviction, and online reads should be resource-isolated so maintenance tasks do not affect online requests.

    7. Build a rollback switch

    Caching is a performance optimization, not a foundational dependency for functional correctness. The system should support gradual enablement by model, node, request type, or traffic percentage, and should be able to quickly disable caching when tail latency degrades. Only with gray release and rollback capability can cache strategies be validated safely.

    How to Diagnose “Cache Gets Slower as You Use It”

    When troubleshooting this kind of problem, it is not advisable to start by modifying the cache algorithm. First, establish a complete timeline. For each request, record at least:

    1. Request arrives
    2. → cache key computation
    3. → local lookup
    4. → remote lookup
    5. → server-side queueing
    6. → network transfer
    7. → data decoding
    8. → memory copy
    9. → cross-GPU synchronization
    10. → model computation
    11. → output generation

    Segmented timing can show whether the bottleneck is in the cache service, the network, the memory system, or cross-GPU synchronization.

    Second, analyze averages separately from percentiles. Normal average latency does not mean the system is healthy. p95, p99, and even higher percentiles better reflect shared-resource contention and tail jitter.

    Finally, run controlled experiments:

    • Disable remote cache and keep only local cache;
    • Keep cache lookup but disallow actual data reads;
    • Recompute directly without accessing any cache;
    • Lower concurrency and observe whether latency recovers;
    • Fix a single GPU or single node to exclude cross-GPU synchronization effects;
    • Test short context and long context separately.

    These experiments can confirm layer by layer whether the problem is insufficient benefit from cache hits, remote service queueing, or distributed synchronization amplifying local latency.

    Conclusion: Cost Accounting Is Central to Cache Optimization

    Caching is not a simple formula of “storage space for compute time.” In LLM inference systems, it also introduces additional costs in networking, memory, scheduling, serialization, concurrency, and synchronization. Especially in multi-GPU and long-context scenarios, a local remote-access latency can be amplified by synchronization into the tail latency of the entire request.

    Therefore, when designing an inference cache, you should not ask only “how high is the hit rate?” You should also answer three questions:

    1. How much computation is actually saved after a hit;
    2. How much system cost is required to retrieve the data;
    3. In the worst case, will the cache block the entire parallel execution chain.

    A truly effective cache system does not make every request read the cache. It uses the cache only when read cost is lower than recomputation cost, and controls risk through tiering, sharding, prefetching, rate limiting, and dynamic bypass mechanisms. Only by treating cache access itself as a computation task that needs optimization can you avoid the anomaly of “the cache being slower than computation.”