When Caching Is Slower Than Compute: The Hidden Cost of Inference Acceleration
This article examines why enabling a shared cache can make LLM inference tail latency worse instead of better. Using a real incident where P99 latency jumped from 3.96 seconds to 17.3 seconds while median latency stayed flat, it explains the four overlooked costs of cache reads—serialization, metadata management, bandwidth contention, and tail amplification—and shows how high data density turns caching from an accelerator into a bottleneck amplifier. It then outlines a practical governance approach: build a cost model before chasing hit rate, use tiered L1/L2/L3 storage, enforce bandwidth budgets, adopt asynchronous prefetching with timeout fallback, and treat cache cost as a first-class observability metric. The conclusion: a mature inference system is judged not by its hit rate but by whether P99 remains controllable once caching is enabled.
1. A Counterintuitive Incident: Tail Latency Quadrupled After Enabling Caching
A team was serving inference for a very large mixture-of-experts (MoE) model on a single node equipped with eight high-performance accelerator cards. To speed up long-context workloads, they added a “shared cache” layer in front of the inference path to store previously computed attention intermediate results, hoping to reuse them when similar requests arrived and skip redundant computation.
The result was unexpected: median latency barely moved, while P99 latency for the slowest 1% of requests jumped from 3.96 seconds to 17.3 seconds. The team’s first instinct was a full rollback.
The core conclusion of this postmortem is a single sentence: reading from a cache has a cost, and that cost has been severely underestimated for a long time. When the read overhead approaches or exceeds the cost of recomputation, the cache degrades from an “accelerator” into an “amplifier”—and what it amplifies is not throughput, but the long tail.
2. Understanding the Workload First: Why “Caching Is Cheap” Is an Illusion
To understand the incident, you first need to see how the model and hardware work together. This scenario uses a class of attention mechanisms that compress key-value information into shared low-rank vectors. Its key property is: the amount of intermediate data that must be written to disk or cache per token is constant, regardless of how many attention heads there are. At FP8 precision, every 256 tokens are packed into one block of roughly 12.4 MB, which works out to about 48.4 KB per token.
These numbers expose the first source of the illusion: 48 KB per token sounds small, but long contexts routinely run into hundreds of thousands of tokens, so a single cache write moves gigabytes of data. Under high concurrency, cache reads can completely saturate both the already-stressed memory bandwidth and the host-device interconnect bandwidth.
An illustrative capacity estimate:
Block size = 12.4 MB / 256 tokensPer-token cost = 48.4 KB100K tokens ≈ 4.84 GB # cache volume for a single request1000 QPS hits ≈ 4.84 TB/s # far beyond any single-node bandwidth limit
The conclusion is straightforward: at this data density, the cache path is not a “free shortcut” but a high-bandwidth data path.
3. Where the Slowness Comes From: Four Overlooked Costs
- Fixed serialization and deserialization overhead. Moving intermediate results from device memory to the shared layer and back requires packing, validation, and alignment. This latency scales linearly with data volume and stacks up on tail requests.
- Addressing and metadata management. Prefix matching, block indexing, hash lookups, reference counting, and eviction decisions are all “bookkeeping” work that creates lock contention and queuing under high concurrency.
- Bandwidth and resource contention. Cache reads compete with ongoing attention computation for the same memory and interconnect bandwidth, slowing the compute side and creating a mutually interfering feedback loop.
- Tail latency amplification. Cache-hit paths typically come with larger memory peaks and longer scheduling queues. Once a request triggers a large data transfer, the whole batch queues behind it, and P99 is blown up by a single blocking point.
Of these four costs, the first two are a “fixed tax” and the latter two are a “congestion tax.” A flat median with a spiking P99 is the signature of the congestion tax.
4. The Right Engineering Posture: Govern the Cache as a Resource with a Cost
4.1 Build a Cost Model Before Chasing Hit Rate
Before shipping, constrain yourself with one sentence: the cache should only be enabled when the recomputation time saved is significantly greater than the read cost.
def should_cache(compute_saved_ms, read_cost_ms, risk_factor=1.5):# risk_factor covers uncertainty from tail latency and resource contentionreturn compute_saved_ms > read_cost_ms * risk_factor
4.2 Tiered Design: Hot Data on the Device, Cold Data Offloaded
- L1: resident on the device, small capacity, lowest latency, holding only the hottest blocks;
- L2: shared layer in host memory, large capacity, but must be prefetched asynchronously;
- L3: external storage (such as object storage or general-purpose distributed caching capabilities), used only for cross-session reuse.
The principle: any cross-device transfer must happen outside the critical path of computation.
4.3 Admission Control and Budgeting: Give the Cache a Bandwidth Quota
Set explicit bandwidth and concurrency budgets for cache reads and writes; degrade to direct recomputation once the budget is exceeded. It is better to miss a cache hit than to let the cache drag the system into congestion.
4.4 Asynchronization and Prefetching
Rewrite “fetch from cache” as “start early, wait only if needed,” with a timeout fallback:
start prefetch -> continue current batch compute -> recompute if not ready when needed
4.5 Observability: Make Cache Cost a First-Class Metric
You must monitor: read amplification ratio, cache-path P99, bandwidth saturation, the proportion of hits that are actually slower, and rollback counts. Without these metrics, the benefits and costs of caching will always be an unaccountable mess.
5. Running It in the Cloud: A General Capability Combination
When building this kind of inference service on Baidu AI Cloud, you can adopt a general combination of capabilities: a container platform to host elastic inference instances, object storage for cold blocks, a message queue for prefetch and invalidation notifications, and logging plus monitoring and alerting to close the loop on cache quality metrics. The key is to make cache governance a platform capability rather than a temporary patch for a single service.
6. Conclusion
Caching is not a free lunch; it is a data path that needs budgeting, scheduling, and observability. When data density is high enough, the cost of reading from the cache approaches or even exceeds recomputation, and at that point “not adding a cache” is the faster option. The measure of a truly mature inference system is not how impressive the hit rate looks, but whether P99 remains controllable once caching is enabled.
