Why Caching Slows Down LLM Inference: Restructuring the Cost of Long-Context Serving

    This article examines a counterintuitive failure mode in large-scale LLM inference serving: enabling a shared cache made tail latency worse instead of better. Using a sparse Mixture-of-Experts (MoE) model with low-rank compressed attention and strongly synchronized context parallelism across 8 accelerators, it explains how remote cache reads introduce hidden costs—serialized writes, network round trips, synchronization amplification, and scheduling mismatches—that pushed P99 latency from about 3.96 seconds to 17.3 seconds. It then walks through a practical remediation plan: fully asynchronous read and write paths, batched and rate-limited writes, tiered hit strategies with prefix-affinity scheduling, cache sharding aligned to the parallel topology, and fine-grained observability. The article closes with four design principles for shared caches in parallel inference systems.

    1. A Counterintuitive Result: Tail Latency Got Worse After Enabling the Cache

    A team serving a very large Mixture-of-Experts (MoE) model ran into a problem that defied common sense. The model has a massive parameter count and uses a sparse activation strategy: each token activates only a subset of the expert networks, expanding model capacity without a proportional increase in computation. The service runs on a single node with 8 high-performance accelerators, each handling part of the parallel workload.

    To speed up long-context processing, the team added a shared cache layer that stores previously computed attention intermediate results, hoping to reuse them when requests share prefixes or overlap, skipping redundant computation. Logically, this looked like a guaranteed win: a cache hit saves compute.

    The measured results were surprising. After enabling the cache, median request latency barely improved, while the slowest 1% of requests (P99) jumped from about 3.96 seconds to 17.3 seconds—more than a 4x degradation. The team briefly rolled the feature back entirely.

    The core conclusion fits in one sentence: reading from a cache is not free, and this cost is routinely underestimated during system design. When the cache read path introduces new synchronization points, shared-resource contention, and queuing, the cache stops being an accelerator and becomes a bottleneck amplifier.

    2. Understanding the Workload: Model Structure and Execution Path Determine Cache Cost

    Diagnosing the problem requires reconstructing how the system actually executes.

    2.1 Compression Characteristics of Attention Intermediate Results

    The system uses a low-rank compressed attention mechanism: each token’s key-value information is projected into a shared low-dimensional latent vector, substantially reducing the volume of intermediate data that must be cached. The key property is that the intermediate data stored per token is decoupled from the number of attention heads and depends only on the compressed latent dimension.

    In the scenario discussed here, the system uses 8-bit floating point, packs every 256 tokens into one cache block, and each block is about 12.4MB—roughly 48.4KB per token. That sounds small, but it scales quickly under long contexts and high concurrency: a 100K-token context corresponds to about 4.8GB of cache data, and running dozens of such requests concurrently pushes cache read/write bandwidth demand into the multi-GB-per-second range.

    2.2 Context Parallelism During Prefill

    Prefill for long contexts has compute that grows roughly quadratically with sequence length, so the system uses context parallelism: a long input is split into shards and processed across all 8 accelerators simultaneously. After processing, the accelerators must exchange intermediate results over a high-speed interconnect so that each one holds the complete context.

    This creates a rigid constraint: the 8 accelerators are strongly synchronized within an iteration, like meshed gears—if any one is slowed down, the other 7 can only idle and wait. Actual throughput is no longer determined by average speed but by the slowest accelerator.

    2.3 Two-Tier Cache Structure

    The cache is designed in two tiers:

    • L1 (near tier): located in local node memory, low latency and small capacity, serving only local requests;
    • L2 (remote tier): located in an external key-value store, large capacity, shared by all inference instances in the cluster—essentially a public library.

    The problem is in L2.

    3. Root Cause Breakdown: Four Hidden Costs of Reading the Cache

    3.1 Serialized Writes: A Single Ledger With One Bookkeeper

    As the shared tier, L2 funnels cache writes from all instances to the same backend. This is like a chain of bubble tea shops where each store keeps its own log (L1), but headquarters requires all logs to be consolidated into one master ledger (L2) maintained by a single accountant. At peak time, eight stores write simultaneously and all queue at that one accountant.

    Queuing on the write side back-pressures the main inference path: when a local cache miss requires backfilling L2, the request must wait for the write to complete or time out, pushing latency from milliseconds to hundreds of milliseconds or even seconds.

    3.2 Network Round Trips and Serialization Overhead

    Every remote cache access involves at least one network round trip, one key construction and lookup, and one serialization and deserialization of a large block. For a 12.4MB block crossing the network, serialization and copy overhead is not negligible; with synchronous blocking calls, this time adds directly to the critical path.

    Illustrative pseudocode shows the anti-pattern:

    1. # Anti-pattern: synchronous remote cache read blocks the critical path
    2. def prefill(request):
    3. kv = l2_get(request.prefix_hash) # network round trip + deserialization, may queue
    4. if kv is None:
    5. kv = compute_attention(request) # compute
    6. l2_set(request.prefix_hash, kv) # synchronous write-back, may queue again
    7. return kv

    3.3 Synchronization Amplification: One Accelerator’s Jitter Becomes Eight Accelerators’ Stall

    Because the 8 accelerators are strongly synchronized, if the parallel shard responsible for a cache read is slowed by L2, the entire node must wait. Single-point jitter is amplified by the parallel structure into a full stall. This is the main mechanism behind P99 degrading from 4 seconds to 17 seconds: most median requests hit L1 or compute directly and are unaffected, while the few that need L2 trigger a global wait and create a long tail.

    3.4 Hit Determination and Scheduling Mismatch

    The reuse value of a shared cache depends on prefix overlap between requests. If the scheduler spreads requests with similar prefixes across different instances, the hit rate drops significantly; conversely, concentrating requests on a few instances to raise the hit rate causes load imbalance. Once the balance between hit gains and scheduling cost breaks, the cache becomes pure cost.

    4. The Fix: Bringing the Cache Back Into Net-Positive Territory

    4.1 Make the Read and Write Paths Fully Asynchronous

    The core principle: cache operations must not appear as synchronous waits on the critical path.

    • Reads become “check local first, then asynchronously prefetch remote”; on a miss, computation starts immediately without blocking;
    • Writes become background batched flushes, with low-value entries allowed to be dropped;
    • All cache calls get strict timeouts and a degradation switch; timeouts are observable and can trip a circuit breaker.
    1. # Optimized: the critical path never waits on the remote tier
    2. def prefill(request):
    3. kv = l1_get(request.prefix_hash)
    4. if kv is None:
    5. kv = compute_attention(request)
    6. l1_put(request.prefix_hash, kv)
    7. async_batched_flush(request.prefix_hash, kv) # background batched write-back
    8. return kv

    4.2 Write Coalescing and Rate Limiting

    Aggregate scattered block writes into batched submissions and apply token-bucket rate limiting to avoid saturating shared storage at peak. Also tier blocks by value: frequently reused prefixes are retained preferentially, long-tail content is evicted outright, trading capacity for hit-rate density.

    4.3 Tiered Hit Strategy and Affinity Scheduling

    • L1 handles the vast majority of hits; L2 serves only as a cross-instance fallback;
    • The scheduler adds prefix affinity: route requests with a common prefix to the same instance to raise the L1 hit rate and reduce dependence on L2;
    • Apply admission control for extremely long contexts so a single huge request does not occupy a synchronization barrier for a long time.

    4.4 Align Parallel Topology With Cache Sharding

    Align cache shards with the rank layout of context parallelism so each rank reads only the segment it owns, reducing cross-accelerator exchange. When necessary, funnel remote access to a few I/O-dedicated ranks that aggregate in local memory and then broadcast, avoiding all 8 accelerators hitting the network at once.

    4.5 Observability: Turn Invisible Costs Into Metrics

    Fine-grained measurement is required, including at least: L1/L2 hit rates, cache read latency distribution (P50/P90/P99), write queue depth, back-pressure occurrences, timeout and degradation ratios, and per-rank wait time. Only by attributing waits to a specific rank and a specific stage can you tell whether an optimization actually works.

    5. Methodology: Four Design Principles for Shared Caches

    1. Cache reads must be degradable: any cache miss should degrade to a normal computation, not a failure.
    2. Writes to the shared tier must be asynchronous, coalescable, and droppable: the first principle for shared resources is protecting the critical path.
    3. Performance in a parallel system is determined by the slowest shard: optimizing the tail is equivalent to optimizing the whole; mean metrics are seriously misleading.
    4. Hit rate is an outcome, not a goal: scheduling affinity, block granularity, and eviction policy jointly determine the hit rate; do not sacrifice load balance for hit rate.

    6. Conclusion

    “Caching is always faster than computing” is common sense that holds only under specific conditions. With the combination of very large MoE, low-rank compressed attention, and strongly synchronized context parallelism, cache reads, serialization, network round trips, and shared writes become a new serial bottleneck that pushes P99 latency up by several times. The real solution is not to abandon caching but to restructure its cost model: asynchronous reads and writes, coalesced and rate-limited writes, alignment with the parallel topology, affinity scheduling to improve effective hits, and thorough observability to continuously validate gains. When building this kind of inference service in the cloud, you can combine general capabilities such as object storage, message queues, container platforms, and monitoring and alerting to support cache tiering and asynchronous pipelines, keeping the engineering focus on cost visibility and tail-latency control.