When the Cache Is Slower Than Recomputation: A Lesson in Distributed Inference Performance

    Caching is often treated as free speed, but in large-scale MoE inference it can backfire dramatically. This article walks through a real production incident where enabling a shared KV cache caused p99 latency to jump from about 4 seconds to over 17 seconds, explains the architectural reasons behind the regression (L2 contention, synchronous prefill parallelism, and hit-rate vs. benefit mismatch), and outlines practical fixes such as tiered caching, overlapping cache reads with computation, benefit-driven admission control, and tail-latency monitoring. It concludes with lessons for engineers on when caching is genuinely worth it—and when it becomes a bottleneck.

    A Counter-Intuitive Production Incident

    In conventional performance wisdom, caching is practically synonymous with “free speed”: store the results of expensive computation, read them back next time, and skip the work. But in the inference service for a very large-scale Mixture-of-Experts (MoE) model, engineers ran into exactly the opposite outcome.

    The service runs on a single node with eight high-performance GPUs. To accelerate long-context processing, the team added a shared KV cache layer to store previously computed intermediate attention results, hoping that similar requests could reuse them and skip recomputation. After enabling the feature, however:

    • The median latency (p50) barely moved.
    • The slowest 1% of requests (p99 latency) jumped from roughly 4 seconds to more than 17 seconds—a degradation of over 4x.

    The team initially rolled the entire cache feature back. The subsequent investigation and redesign eventually produced a valuable engineering paper. Its core conclusion fits in one sentence: reading a cache has a cost of its own, one that is amplified dramatically in distributed environments and is often severely underestimated.

    Understanding the System Architecture

    To understand why the cache held the system back, you first need to see the architectural constraints of this inference system.

    MLA Attention and KV Data

    The model uses an MLA (Multi-head Latent Attention) style design: each token’s Key/Value information is compressed into a shared, low-rank latent vector. The benefit is that regardless of how many attention heads the model has, the amount of intermediate data stored per token is fixed and small.

    In this system, KV data is stored in FP8 precision, packed into blocks of 256 tokens. A single block is about 12.4 MB, or roughly 48 KB per token. The data is small enough that “remotely storing the KV cache in a shared store” looks entirely feasible from a capacity standpoint—but capacity feasibility does not mean the access path is free.

    Prefill-Stage Context Parallelism

    The prefill stage for long texts is extremely compute-intensive, so the system uses prefill context parallelism (PCP): a long text is split and processed across multiple GPUs, after which the GPUs exchange intermediate results over the network so that each one has the full context.

    This creates a critical structural property: the eight compute processes (ranks) on the node interlock like gears—every one of them must advance in lockstep at each step. If one rank slows down, the other seven idle while waiting. Overall speed is determined by the slowest rank.

    A Two-Tier Cache Architecture

    The cache has two tiers:

    • L1: close to the GPU, stored in local memory—fast but limited in capacity, and private to each rank.
    • L2: stored in a remote key-value database—large in capacity and shared by all inference engines, like a “public library.”

    The problem lies squarely in L2.

    Root Cause: Hidden Contention in the Shared Cache

    Here’s an intuitive analogy: imagine a bubble tea chain where each branch keeps its own ledger (L1), but for consolidated auditing at headquarters, every branch’s entries must also be written into one master ledger (L2)—and there’s only one accountant managing that ledger. When business picks up, eight branches all try to post entries at once, and everyone queues up at the accountant’s desk.

    Translated into technical terms, the bottleneck decomposes into several compounding factors:

    1. A concentrated point of contention. L2 is a single shared resource for all ranks. During prefill, eight ranks read and write it at high frequency, requests queue up on the cache server, and individual rank reads develop long-tail latency.

    2. Synchronous amplification. Because PCP requires all ranks to synchronize step by step, any rank that hits the slow L2 path drags the entire node along. The cache’s tail latency propagates through the “weakest link” effect, ultimately surfacing as a spike in overall p99.

    3. Mismatch between hit rate and benefit. Even on a cache hit, one remote read can take as long as—or longer than—recomputing the result locally. That is the essence of “the cache is slower than computation”: a cache’s effectiveness is determined not by its hit rate, but by the ratio of read cost to recomputation cost.

    4. The median hides the problem. Most requests take the L1 fast path or the normal computation path after a miss, so p50 looks perfectly healthy. Only the requests that land inside the L2 contention window absorb the full cost. This kind of long-tail regression is easy to miss with conventional monitoring.

    Redesign: Making the Cache Actually Help

    The redesign directions from the paper all revolve around lowering read cost and eliminating centralized contention, and they apply to any distributed caching scenario:

    4.1 Tiering and Locality

    Keep hot data local (L1) as much as possible; only data that genuinely needs cross-engine reuse should go into the shared tier. On the read side, prefer local lookups first and asynchronously warm remote data, avoiding synchronous remote calls on the critical path.

    4.2 Weakening Synchronization Dependencies

    For cases that require cross-rank coordination, overlap cache reads with other computation so the wait is hidden behind useful work. Alternatively, set timeouts and fallback policies for cache reads—on timeout, abandon the cache and recompute directly, using bounded compute cost to cap the long-tail risk.

    4.3 Benefit-Driven Admission Control

    Not everything is worth caching. Based on historical reuse patterns, only write blocks with a high probability of reuse and controllable read cost into L2, reducing write pressure and storage bloat in the shared tier.

    4.4 Tail-Oriented Monitoring

    For caches, p50 has almost no diagnostic value. Monitor p95/p99, queue depth, and the distribution of per-rank read latency, and distinguish the latency composition of “hit but slow” requests from “miss and recompute” requests.

    The core idea can be expressed with simple pseudocode:

    1. def get_kv_block(token_ids):
    2. block = l1_local_cache.get(token_ids)
    3. if block:
    4. return block # Local hit: fastest path
    5. if estimated_read_cost(l2) < estimated_recompute_cost(block):
    6. block = l2_shared.get(token_ids, timeout=T)
    7. if block:
    8. return block # Remote hit, and worth the cost
    9. return recompute(token_ids) # Otherwise recompute as the fallback

    Lessons for Engineers

    The value of this incident goes well beyond a single case; it corrects several widely held “common-sense” beliefs:

    1. Caching is not free. Every cache read involves serialization, network round trips, and queuing. In distributed systems, these costs can be amplified exponentially.
    2. Hit rate is not benefit. Whether a cache is worth it should be judged by end-to-end latency and throughput—not by the pretty numbers on a hit-rate dashboard.
    3. Watch the tail, not the mean. p99 is often the true boundary of user experience and the first thing to collapse in capacity planning.
    4. Caches need a fallback path. Any shared dependency can become a contention point; the system must be able to fall back to direct computation when the cache slows down.

    At its core, caching is a transaction in performance engineering: trading storage for computation. And when computation itself is already fast enough—especially with today’s rapidly improving compute—the exchange rate changes. As engineers, before introducing any cache, we need to honestly do the math on one question: is the cost of reading it really lower than the cost of recomputing? The answer to that question determines whether the cache is an accelerator or a drag.