When Caching Slows Down Inference: The Hidden Cost in Long-Context Serving
Caching is often assumed to speed up long-context LLM inference, but shared caches can do the opposite. Based on a real rollback involving a large-scale MoE model, this article explains why median latency stayed flat while p99 tail latency jumped from about 3.96 seconds to 17.3 seconds. It breaks down the execution path of compressed attention (MLA), context parallelism across 8 ranks, and shared L2 key-value storage, then details the five causes of amplified tail latency: synchronous write amplification, the parallel-group bucket effect, low hit rates, capacity-driven thrashing, and missing admission control. Readers will find a practical engineering checklist covering asynchronous batched writes, sharding and aggregation, admission and prioritization, eviction policies, tiered coordination, and observability, along with a safer rollout path that uses tail latency rather than average latency as the acceptance criterion.
1. The Counterintuitive Result: Caching Is Not Inherently Faster
In long-context inference serving, teams often add a shared cache to store already-computed attention intermediates, hoping similar requests can reuse them. One team built a shared cache for a hyperscale Mixture-of-Experts (MoE) model, an architecture where different expert subnetworks handle different tokens. The result: median latency barely moved, but tail latency for the slowest 1% of requests rose from about 3.96 seconds to 17.3 seconds. The team had to roll it back.
The core takeaway is simple: reading from a cache is not free, and that cost is routinely underestimated. When cache writes, lookups, network synchronization, and parallel-group waiting stack up, a cache can shift from “saving compute” to “creating queues.”
2. Understand the Execution Path Before Judging Cache Benefits
The system uses a compressed attention mechanism commonly known as MLA. Each token’s key-value information is compressed into a shared low-rank vector, making the per-token cache footprint fixed and small. In the example, FP8 precision packs 256 tokens into one block, with each block taking roughly 12.4MB, or about 48.4KB per token on average.
Long-context prefill also enables context parallelism: a long input is split across 8 ranks, and each rank must communicate and synchronize after computing. The parallel group behaves like a set of gears: if one rank is slow, the other seven wait. If the cache lives in a shared key-value store (L2) used by all engines, write throughput and lock contention become bottlenecks, like eight stores sharing a single accountant.
Illustrative capacity estimate:
Cache size per request ≈ number of tokens × 48.4KBWith 8-way parallelism, peak write per request ≈ cache size per request (aggregated after sharding)If shared storage write bandwidth is B, theoretical max concurrent write requests ≈ B / cache size per request
3. Why Tail Latency Gets Amplified
- Synchronous write amplification: Requests wait for L2 to persist before completion, so I/O jitter translates directly into tail latency.
- Parallel-group bucket effect: A slow cache operation on one rank holds back the entire group.
- Low hit rate: Similar requests do not share the same prefix, so the hit rate stays low and the cache sees more writes than reads.
- Capacity-driven jitter: Hot blocks are evicted frequently, forcing repeated recomputation from source.
- No admission control: Every request writes to the cache indiscriminately, competing for the same resources during peaks.
4. Engineering Remediation Checklist
- Asynchronous and batched writes: Return results first, merge writes in the background, and set queue limits with timeout-based dropping.
- Sharding and aggregation: Write per rank to avoid single-point contention; aggregate reads in parallel.
- Admission and prioritization: Cache only requests with high expected reuse and moderate length; throttle during peaks.
- Capacity and eviction policy: Evict based on block heat, recency, and request characteristics, while reserving space for hot blocks.
- Tiered coordination: Let L1 handle low-latency hits and L2 handle cross-engine sharing, with clear consistency boundaries.
- Observability: Monitor hit rate, read/write latency, queue length, eviction rate, and parallel-group wait time separately, with p50/p95/p99 attribution.
5. Conclusion
Whether caching is worth enabling depends on whether the compute time saved exceeds the read/write and synchronization cost. In scenarios with long contexts, high parallelism, and heavy shared-storage contention, treat the benefits of a synchronous cache with default skepticism, and use asynchronous writes, sharding with aggregation, and admission control to bring costs into a predictable range. The safer engineering path is to build latency attribution first, run a small-traffic canary next, and use tail latency rather than average latency as the final acceptance criterion.
