When Caching Slows Down LLM Inference: Understanding P99 Latency Degradation
This article examines why adding a shared cache to a large-scale MoE LLM inference service failed to improve median latency while pushing P99 latency from 3.96 seconds to 17.3 seconds. It explains why long-context, expert-routed inference is especially sensitive to caching, breaks down five real causes of tail latency spikes, and offers a measurable decision framework based on effective hit rate, cache tax, and memory contention. Readers will find a phased optimization path covering shadow runs, key design, admission control, asynchronous paths, and tail governance, plus guidance on when to abandon shared caching altogether.
1. The Counterintuitive Result: Caching Is Not Always a Win
In general computing, “trade memory for time” is an axiom that rarely needs proof. In large language model (LLM) inference serving, however, that assumption can be turned upside down.
One team served a very large mixture-of-experts (MoE) model on a single node equipped with eight high-performance accelerators. The workload included a large volume of long-text requests. To avoid repeated computation, they added a shared cache layer that stored previously computed attention-related intermediate data, expecting similar requests to reuse it directly.
The results defied expectations: median latency barely improved, while the slowest 1% of requests (P99 latency) rose from 3.96 seconds to 17.3 seconds. The team initially rolled the whole thing back.
The value of this case is not that “caching is useless.” It exposes a widely overlooked fact: the benefit of a cache is probabilistic, but its cost is deterministic. When the hit rate is low, the cost is high, and the cost distribution is uneven, a cache degrades from an accelerator into a latency amplifier.
Note that this article is not about any specific product or vendor. It discusses a general industry problem: under long-context, multi-expert routing inference architectures, under what conditions a shared cache should be enabled, how to measure it, and how to govern tail latency.
2. Why MoE Long-Text Inference Is Especially Sensitive to Caching
The core idea of MoE is to let different expert subnetworks handle different token types and semantic patterns, scaling parameter count with limited growth in computation. This has two direct consequences.
First, the computation path is data-dependent. Each token is routed differently and activates a different set of experts, so “similar requests” do not mean “similar computation graphs.” If the cache key is based only on the text prefix, requests that are semantically close but routed completely differently can easily be treated as hits.
Second, memory and bandwidth are hard constraints. Attention intermediate data grows superlinearly with sequence length, and this portion of memory usage is enormous in long-text scenarios. Caching essentially trades memory and bandwidth for computation, and in a single-node, eight-accelerator environment, spare memory is often tighter than expected.
A schematic capacity relationship looks like this:
cache usage ≈ number of entries × size of one entry's intermediate datasize of one entry ≈ layers × heads × sequence length × head dimension × bytes per value
As sequence length grows from thousands to tens of thousands, the size of a single entry scales linearly, while the number of entries typically grows with request volume. Multiplying the two makes memory pressure very easy to trigger.
3. Five Real Causes of the P99 Spike
3.1 Low hit rate means paying the full overhead
Cache writes, serialization, key computation, and eviction maintenance are deterministic costs, while hits are a probabilistic benefit. If the hit rate is only a single-digit percentage, the system effectively charges most requests an extra tax.
3.2 Tail requests absorb the “public cost” of cache maintenance
Unchanged median latency combined with exploding P99 is a classic queuing-theory signal: average resource usage barely changes, but variance is amplified. Cache eviction, defragmentation, and cross-request lock contention concentrate on a few requests, which then become the bearers of tail latency.
3.3 Memory contention triggers a chain reaction
Once the cache takes memory, the space available for batching shrinks, forcing the scheduler to reduce concurrency and driving up queueing time. Worse, as usage approaches the limit, swapping and recomputation kick in, creating a triple penalty of “cache miss + recomputation + paging.”
3.4 Consistency checks cancel out the reuse benefit
To guarantee correctness, context consistency must be verified before a hit is accepted. Verification itself requires traversing the prefix and comparing hashes; for long text, this overhead can be comparable to direct computation, cancelling or even negating the benefit.
3.5 Resource contention with expert parallelism
MoE inference relies on efficient parallelism across expert shards and overlapping communication. The cache’s extra memory copies and synchronization points break the existing pipeline overlap, so communication can no longer be hidden behind computation, and end-to-end time grows instead.
4. A Verifiable Decision Framework
Do not use “enable caching or not” as the decision unit. Use “effective savings per unit of cost” as the decision unit. Start by defining observable metrics:
- Hit rate: measured by request count and by token count separately; the two often lead to opposite conclusions;
- Effective hit: a hit that passes the consistency check and saves positive end-to-end time;
- Cache tax: (write + eviction + verification + copy time) / total time;
- Tail metrics: P95, P99, P99.9, plus timeout rate and retry rate;
- Resource metrics: peak memory, fragmentation rate, swap count, and batch size distribution.
The decision rule can be written as one inequality:
time saved per hit × effective hit rate > cache tax + queueing increase from memory contention
Only when this holds steadily within the target load range does the cache have production value.
5. A Phased Optimization Path
Phase 1: run in shadow mode. The cache is write-only; observe the capacity curve and eviction frequency, and confirm that memory leaves a safety margin. Reserve a clear buffer for burst traffic.
Phase 2: tighten key design. The key should combine the model identifier, weight version, a stable digest of the context prefix, precision, and parallelism configuration, avoiding false reuse of semantically similar requests.
Phase 3: add admission control and quotas. Set a hard capacity limit and a per-request usage limit. Long-text requests can be excluded from the cache by default, leaving resources for high-frequency reuse of short requests.
Phase 4: move the cache off the critical path. Make writes and evictions asynchronous to avoid introducing synchronization points on the critical path. A failed read must fall back to normal computation quickly; never block for a long time on hit determination.
Phase 5: govern the tail. Set timeouts and degradation switches for cache-related operations, and use monitoring, alerts, and log services to locate the sources of long tails. If necessary, apply tiered rate limiting by tenant or request type.
Schematic degradation logic:
def cached_attention(ctx, key):if len(ctx.tokens) > LONG_TEXT_THRESHOLD:return compute(ctx) # bypass the cache for long textentry = cache.get(key, timeout=LOOKUP_BUDGET)if entry is None or not verify(ctx, entry):return compute(ctx) # fast fallback to avoid blockingreturn entry.value
6. When to Abandon Shared Caching
If request prefixes have low repetition, context length distribution is heavily long-tailed, spare memory is insufficient, or model routing is highly data-dependent, the expected benefit of a shared cache is likely negative. In that case, safer directions include: optimizing batching and scheduling policies, improving parallelism and communication overlap efficiency, compressing intermediate data precision, scaling elastically on container platforms, or moving non-critical paths to asynchronous processing with object storage and message queues. A cache is just one tool in the toolbox, not a default requirement.
7. Conclusion
What this case really overturns is not “caching is useful” but the habitual assumption that “caching is necessarily useful.” Under long-text and mixture-of-experts architectures, caching is a system capability that must be measured, capped, and managed with degradation. Basing decisions on effective hit rate, cache tax, and tail latency is what makes optimization actually improve user experience, instead of quietly shifting cost onto the slowest 1% of requests.
