Why Caching Can Slow Down Tail Latency in Large-Scale LLM Inference

    This article explains why a shared cache that reduces repeated computation can still increase tail latency in large language model inference. It covers how prefix caching works for long-context requests, why cache reads have real costs in mixture-of-experts models with context parallelism, and how shared cache bottlenecks, queuing, and device synchronization can amplify slow requests. It also describes how to judge whether a cache read is worth it, design cache paths that can degrade gracefully, and monitor latency beyond hit rate.

    In large language model inference systems, caching is usually treated as an important way to reduce repeated computation, increase throughput, and shorten response time. In workloads with long texts, multi-turn conversations, and heavily reused prompts, saving intermediate attention results that have already been computed looks like an obvious optimization.

    However, a cache is not automatically a speedup.

    In one inference service for a very large mixture-of-experts model, the system ran on a single node with multiple high-performance accelerators. After the engineering team added a shared cache for long-context requests, the median latency of typical requests changed little. But the slowest requests got much worse. Tail latency rose from a few seconds to more than ten seconds, and the team eventually had to disable the cache temporarily.

    This result shows a fact that is easy to overlook: reading from a cache is itself an execution path with a cost. If cache access involves remote memory, serialization, network transfer, concurrent queuing, and multi-device synchronization, the computation time saved may be fully offset by these extra costs. In the worst case, the cache slows down the entire inference process.

    1. Background: Why Long Contexts Need Caching

    Large model inference usually has two stages:

    1. Context processing: The model reads the user input, conversation history, and relevant documents, then computes the intermediate state for each token.
    2. Token-by-token generation: The model generates output step by step from the existing context. Each new token requires access to the attention-related data saved earlier.

    For short texts, recomputation is often acceptable. When the input reaches thousands or even tens of thousands of tokens, the upfront computation consumes a large amount of compute and memory bandwidth. If multiple requests share the same or highly overlapping prefixes, the system can try to reuse existing results and avoid processing the same content again.

    This is the basic idea behind prefix caching, or attention state caching:

    1. Request input
    2. │
    3. ├── Cached prefix ──> Reuse the intermediate results directly
    4. │
    5. └── Uncached part ──> Run model computation

    Ideally, after a cache hit, the system only needs to process the new content. This reduces computation and can shorten time to first token.

    However, this model assumes one precondition: the total cost of accessing the cache must be lower than the cost of recomputation. Once the cache is located remotely, or the cost of hit checks, data movement, and multi-device synchronization becomes too high, the benefit drops quickly.

    2. Model Architecture Determines How the Cache Is Accessed

    Modern large models often use a mixture-of-experts architecture. The model contains multiple expert modules, and each token activates only some of them. This allows the parameter count to grow while keeping the actual computation per inference step under control.

    At the same time, some models use compressed attention mechanisms that compress the key and value information for each token into a smaller latent representation. Compared with traditional multi-head attention, this design significantly reduces cache memory usage, which makes long-context inference more practical.

    In some real-world deployments, the system packs several tokens into fixed-size data blocks and stores them in a low-precision format. The cache data for a single token is already small. However, when context length, the number of concurrent requests, and cache retention time all increase, the total data volume can still be very large.

    For this reason, cache systems often use a tiered design:

    • Near cache: Located close to the inference process or the accelerator. It is fast but has limited capacity.
    • Shared cache: Located in host memory or in a separate cache node. It has larger capacity and can be accessed by multiple inference instances, but it requires thread scheduling, memory copies, or network communication.
    • Persistent storage: Has the largest capacity, but its access latency is usually too high to participate directly in real-time inference.

    The key to a tiered design is not whether a cache exists. It is whether the cost of moving data between tiers is under control.

    3. Context Parallelism: Why One Slow Point Stalls All Devices

    Long-text inference often uses context parallelism, which splits one input across multiple accelerators. Each device handles part of the tokens. However, attention computation needs to account for the full context, so the devices must exchange data and synchronize.

    The process can be summarized as:

    1. Device A: processes segment 1 ─┐
    2. Device B: processes segment 2 ─┼─> Collective communication ─> Continue computation
    3. Device C: processes segment 3 ─┤
    4. Device D: processes segment 4 ─┘

    In this architecture, computation is usually not completed independently on each device. It consists of repeated rounds of local computation, collective communication, and further computation. If one device waits, the others may also be forced to stall.

    This amplifies cache problems.

    Suppose a request issues cache reads on several devices at the same time. If one device does not receive its data because the cache service is congested, the other devices cannot proceed to the next step, even if they have finished their local preparation. In the end, a local delay in cache access is magnified by the synchronization mechanism into latency for the whole request.

    As a result, a cache read that adds only tens of milliseconds from a single device’s point of view can become the following in a multi-device setting:

    1. Single-device cache latency
    2. ×
    3. Number of device synchronizations
    4. ×
    5. Slowest branch in parallel execution

    This is why tail latency is more likely to worsen than average latency.

    4. The Core Bottleneck of Shared Caches: Centralized Queuing

    A shared cache usually relies on a unified key-value service to store and look up data. Its advantages are large capacity and shared access for multiple inference processes. However, it can easily become a centralized bottleneck.

    A typical access flow looks like this:

    1. Inference process
    2. │
    3. ├─ Generate cache key
    4. ├─ Query shared cache
    5. ├─ Receive cache metadata
    6. ├─ Fetch cache blocks
    7. ├─ Copy to local memory or accelerator
    8. └─ Synchronize with other devices

    As concurrent requests increase, many of them may hit the same shared service at once. At that point, the bottleneck may not be storage capacity. It may be any of the following:

    • Request queuing;
    • Key lookup and hit determination;
    • Data serialization and deserialization;
    • Number of network connections;
    • Memory copies;
    • Splitting and reassembling cache blocks;
    • Background eviction and space reclamation;
    • Lock contention among multiple inference instances.

    When cache blocks are large, a single hit is not a lightweight key-value lookup. It can require transferring a large amount of data. If multiple devices read the same prefix at the same time, the system may also transfer the same content repeatedly, which creates hotspot amplification inside the cache service.

    This is similar to several branch stores asking headquarters for the same ledger at the same time. The ledger avoids each store reorganizing the data on its own. But if every store must wait in line for one bookkeeper, overall efficiency drops.

    5. Why the Median Barely Changes but p99 Gets Much Worse

    The median reflects typical requests, while p99 reflects the slowest fraction. When a cache system has problems, the two often look different.

    At low load, the cache service has not formed a noticeable queue, so cache hits may deliver some benefit. Some requests become faster and others stay about the same, so the overall median looks normal.

    Under high concurrency or traffic bursts, however, cache access starts to queue. Request latency no longer depends only on model computation time. It also depends on how many requests are ahead when it reaches the cache service. A small number of requests may then wait at each of these steps:

    1. Waiting for a cache connection;
    2. Waiting for a cache query;
    3. Waiting for data transfer;
    4. Waiting for a local copy;
    5. Waiting for other devices to finish synchronization;
    6. Waiting for the model scheduler to reschedule execution.

    These waits have a clear long-tail pattern. The average may increase only slightly, but p99 and p99.9 rise quickly.

    Therefore, evaluating a cache should not rely only on average latency or median. It is also necessary to track:

    • Cache hit rate;
    • Percentile latency for hit and miss requests;
    • Cache read queuing time;
    • Data transfer time;
    • Number of cache blocks read per request;
    • Completion time gaps across devices;
    • CPU, memory, and network utilization of the cache service;
    • Inference queue length and scheduling wait time.

    6. A Correct Way to Judge Benefit: Is the Cache Read Worth It?

    A cache strategy should not be decided by hit rate alone. A cache entry may have a high hit rate, but if reading it costs too much, it may bring no real value.

    A simple benefit model is:

    1. Net cache benefit
    2. = Avoided computation time
    3. - Cache query time
    4. - Data transfer time
    5. - Data copy time
    6. - Extra scheduling and synchronization overhead

    A cache is worth enabling only when the net benefit is greater than zero.

    Requests can be further divided into several types:

    1. Short-context requests

    Recomputation is cheap, so cache reads may account for a larger share of total cost. These requests are usually not suitable for remote shared cache access.

    2. Long-prefix, highly repeated requests

    If the prefix is long and the hit probability is stable, the benefit of caching is more noticeable. These requests should be prioritized for caching.

    3. Requests with small cached results

    Data movement is cheap, so even if the computation saved is limited, the net result may still be positive.

    4. High-concurrency hotspot requests

    These requests have high hit rates but can easily congest the cache service. They may need replicas, sharding, or local warm-up strategies.

    7. Optimization Directions: Making the Cache Path Controllable

    1. Prioritize local caching

    Frequently used, short-lived, and hot data should be kept close to the inference process. The shared cache provides capacity, and the local cache provides low-latency access.

    Common practices include:

    • Setting a limited-size local cache for each inference instance;
    • Warming up recent high-frequency prefixes;
    • Using tiered eviction policies;
    • Splitting large data blocks into cache units that can be managed independently;
    • Avoiding a remote cache lookup on every request just to confirm state.

    2. Set cache access thresholds

    Not every request should query the cache. Decisions can be based on prefix length, historical hit rate, and estimated computation cost:

    1. If:
    2. Estimated computation time saved > Estimated cache access cost + safety margin
    3. Then:
    4. Query the shared cache
    5. Else:
    6. Run computation directly

    The safety margin absorbs burst queuing and tail latency fluctuation.

    3. Avoid repeated reads

    Devices within the same request should not blindly fetch the same data again. A coordinator process can fetch each cache block once and distribute it through efficient device-to-device communication. Alternatively, cached data can be laid out across devices so that repeated transfers are reduced.

    4. Control concurrency to the cache service

    A shared cache needs rate limiting and backpressure. When the cache service approaches saturation, the system should reduce read concurrency actively instead of letting large numbers of requests queue without limit.

    The system should also separate:

    • Query requests;
    • Data read requests;
    • Cache write requests;
    • Eviction and background maintenance tasks.

    Different types of operations should not block each other heavily.

    5. Make cache failures degrade gracefully

    A cache should be an optimization path, not a dependency for correctness. When a timeout, connection failure, or service congestion occurs, the request should fall back to the normal computation path instead of waiting indefinitely.

    A reasonable degradation flow is:

    1. Attempt cache read
    2. │
    3. ├─ Success: Reuse the result
    4. ├─ Timeout: Abandon the cache and compute directly
    5. ├─ Service error: Temporarily trip the circuit breaker
    6. └─ Data validation failure: Discard the cache entry and recompute

    The cache timeout must be short enough. Otherwise, waiting for the cache to avoid computation can backfire.

    8. Monitoring: Do Not Track Hit Rate Alone

    Cache hit rate is an important metric, but it cannot prove on its own that a cache is effective. At minimum, the following dimensions should be observed:

    Request level

    • Time to first token;
    • Total response latency;
    • p50, p90, p99, and higher percentiles;
    • Latency of hit and miss requests, measured separately;
    • Context length of the request;
    • Generation length.

    Cache level

    • Query time;
    • Actual read time;
    • Data copy time;
    • Size of each read;
    • Queue length;
    • Timeout rate;
    • Eviction rate;
    • Distribution of hot keys.

    Device coordination level

    • Computation time on each device;
    • Communication time per round;
    • Difference between the fastest and slowest devices;
    • Synchronization wait time;
    • Device idle ratio.

    If the cache hit rate is high but the tail latency of hit requests is worse, the problem is usually not in the caching algorithm itself. It is more likely in the access path, concurrency control, or device synchronization.

    9. Conclusion: Caching Is a Computation Strategy With a Cost

    “Store the result and read it next time” sounds simple, but in large model inference, cache operations involve the memory hierarchy, network transfer, data layout, concurrent scheduling, and multi-device synchronization. Especially in long-context and context-parallel settings, the slowest step in cache access can be amplified across the whole system.

    For this reason, cache systems should follow three principles:

    1. Compare the cost of cache access with the cost of computation first: Reuse only makes sense when the cache read is actually cheaper.
    2. Watch tail latency before average gains: System stability is often determined by the slowest requests.
    3. Guarantee graceful degradation before chasing high hit rates: A cache should improve performance, not become a new single point of blocking.

    An efficient cache does not store as much as possible. It keeps the right data in the right place, and under an appropriate load, it retrieves that data faster than recomputation would. Only when cache access cost is included in a complete end-to-end performance model does a cache move from a potential bottleneck to a reliable inference accelerator.