When Cache Reads Are Slower Than Recompute: The Hidden Cost of Inference Acceleration

    This article examines a counterintuitive production incident where adding a shared cache to a large-scale MoE inference service left median latency unchanged but pushed p99 latency from 3.96 seconds to 17.3 seconds. It breaks down the often-underestimated costs of a cache hit, explains why tail latency explodes while the median stays flat, and outlines five practical fixes—total-cost hit decisions, admission control, tiering, tail-latency guardrails, and observability—plus a safer approach to capacity planning. The key takeaway: cache benefits show up in the average, but costs show up in the tail.

    1. A Counterintuitive Production Incident

    A team was building an inference service for a very large Mixture-of-Experts (MoE) model—an architecture that lets different parts of the model handle different types of tasks, expanding model size without a proportional increase in compute. Each node was equipped with 8 high-performance accelerator cards. To speed up long-context processing, they added a shared cache layer in front of the inference pipeline to store previously computed attention data, hoping to reuse it for similar requests and skip redundant computation.

    The post-launch numbers were surprising: median latency barely moved, while the slowest 1% of requests (p99 latency) jumped from 3.96 seconds to 17.3 seconds. The team ended up rolling back the entire caching feature.

    The value of this case is that it flips a long-overlooked assumption: reading from a cache is not free, and this cost is routinely underestimated during capacity planning. When the cost of a single read approaches or exceeds the cost of recomputing, the cache degrades from an accelerator into a decelerator.

    2. The Overlooked Cost: Why Cache Reads Are Expensive

    To understand the incident, break a single cache hit into a sequence of quantifiable actions:

    1. Key generation: normalize the request context, align prefixes, tokenize, then compute a hash. For long contexts, this step scans every token.
    2. Lookup and addressing: locate the entry within a multi-level index structure, involving random memory access and pointer chasing.
    3. Data movement: move the attention tensors from the cache medium into memory usable by the compute units. The size of attention data grows with sequence length, so the transfer volume is not small.
    4. Deserialization and layout conversion: the compact storage layout often differs from the blocked layout required for computation, requiring a reordering pass.
    5. Validation and consistency handling: confirm the entry has not been evicted and the version has not expired, falling back to the recompute path if necessary.

    Schematically, the decision can be written as an inequality:

    1. use_cache if and only if T_lookup + T_transfer + T_reorder < T_recompute

    The problem is that all three terms on the left degrade simultaneously when capacity is tight, while the term on the right becomes very cheap when batching is sufficient and operators are warmed up. What was supposed to be a sure win becomes a possible loss.

    3. Why the Median Is Fine but p99 Explodes

    This is the most instructive part of the whole story. A cache does not affect the system uniformly; its impact is amplified into the tail through queuing effects:

    • Higher variance in service time. A hit is a fast path and a miss is a slow path; mixing the two turns the service-time distribution from unimodal to bimodal, significantly increasing variance.
    • Head-of-line blocking. A request performing a large transfer or recompute occupies execution resources, and everything queued behind it waits.
    • Cache miss storms. When a hot entry is evicted, many similar requests hit the origin at once, forming a thundering herd and multiplying instantaneous load several times over normal levels.
    • Memory pressure and paging. The cache consumes memory that could otherwise be used for activations and KV space, triggering more frequent paging in and out and further stretching the tail.
    • Background maintenance interference. Eviction, flushing, and compaction tasks compete with foreground inference for bandwidth.

    The intuition from M/M/1 makes it clear: as utilization ρ rises from 0.7 to 0.85, average queuing time grows several times over, and p99 grows far more steeply than the mean. The mean lives in a linear world; the tail lives in an exponential one.

    4. Five Actions to Turn the Cache Back into an Accelerator

    1. Make the hit decision on total cost

    Do not compare only the compute saved; count lookup, transfer, reordering, and validation as well. In practice, instrument each read to produce a real-time ratio of saved_ms to overhead_ms, and skip the cache entirely when it falls below a threshold.

    2. Admission control: not every request deserves the cache

    Enable caching only where the benefit is certain—for example, very long contexts, highly overlapping prefixes, and requests with high recompute cost. Send short requests and low-overlap requests straight to recompute. A lightweight estimator can help:

    1. estimated_gain = recompute_cost * prefix_overlap_ratio - cache_access_cost
    2. admit if estimated_gain > margin

    3. Tiering and locality

    Place hot data in the tier closest to compute and push cold data down to higher-capacity media; batch and prefetch along the transfer path to avoid per-item random access. Define explicit promotion and demotion policies between tiers rather than relying on a single LRU policy for everything.

    4. Tail-latency guardrails

    Set timeouts and fast fallback for the cache path, recomputing on timeout; apply concurrency convergence (single-flight) on origin fetches so that concurrent misses on the same key trigger only one recompute; and rate-limit and stagger background maintenance tasks.

    5. Observability first

    At minimum, collect hit rate, the distribution of hit benefits, read-latency percentiles, bytes transferred, eviction rate, origin-fetch concurrency, cache occupancy, and page-in/page-out counts. Without these metrics, any cache rework is a blind change.

    5. Capacity Planning Done Right

    Many teams estimate the speedup as “average hit benefit × hit rate,” which is dangerous. A safer approach is to load-test the tail: ramp up load gradually at the target QPS, watch for the p95/p99 inflection point, and find the utilization ceiling at which the system starts to be dragged down by the cache, leaving a safety margin. Also treat cache memory as a resource competing with KV space and make an explicit budget split, instead of giving it “whatever is left over.”

    6. Conclusion

    A shared cache is not a free lunch. Its benefit shows up in the mean, and its cost shows up in the tail; the bill does not come due at the moment of a hit, but at the moment capacity gets tight. For teams running inference services, the right approach is: account for the total cost first, then apply admission control, configure tiering, install guardrails, and validate with tail latency rather than the mean. Once the cost of cache reads is honestly accounted for, the lesson of that jump from 3.96 seconds to 17.3 seconds will not be paid for a second time.