KV cache economics calculator

Under these assumptions...

Suppose you are hosting on and serving a batch of that each consist of , represented at precision.

Assume 90% cache hit rate, with cached expiry duration of .

Note: A cache miss still pays recomputation costs.

Advanced assumptions Hardware, indexer precision, and storage profiles Edit

Selected hardware, per accelerator

Offload tiers

DDR
SSD
HDD

The optimal strategy is to keep the cache in DDR.

Expected cost for one future lookup
Strategy Storage Costs Computation Costs Expected total

Cost of each caching strategy against TTL

Expected cost by cache TTL Five expected-cost curves across a continuous cache TTL range, with the current TTL and cheapest-strategy crossovers marked.

Retrieval latency by strategy

Retrieval latency by caching strategy Retrieval latency for each available caching strategy, compared with recomputation latency.

Follow the calculation

Expected cost by strategy

Apply the cache bytes, cluster price, hit rate, and TTL to each path. 0 seconds
Minimum feasible total Winner

Reason

KV Cache Economics: First Principles

In Progress

I'll rewrite this later to thread the relevant parts throughout the piece instead of explaining the full analogy up front. But just keeping here for reference.

Here’s a simple analogy: imagine you’re reading a book to write a report, taking notes on scratch paper as you go. Ordinarily you’d throw that scratch paper away after a session, but if you keep it on your desk, you can consult your notes instead of re-reading the whole thing. That’s what we call a “cache hit.” The tradeoff is that your notes consume scarce desk space. You can file those notes in a cabinet instead, which costs cheaper space but makes retrieval slower. And keeping the notes only pays off if you (or a colleague) will ask for that book again.

In a transformer, the "notes" you take while reading are the Key-Value (KV) states computed during the forward pass. Inference must generate these states anyway — ie. the model needs “scratch paper” to generate output tokens. But taking those notes is not the same as storing them for later reuse, and that’s where caching comes into play. Now you consider retention policies (how long the paper stays on the desk), indexing (a label so you can find it), routing (which cabinet to check), among other considerations.

1. Cache size is architecture-dependent

For standard GQA/MHA:

M_KV = N_seq L N_layers (2 H_KV d_head) b

For MLA:

M_MLA = N_seq L N_layers (r_KV + d_RoPE) b

And newer recurrent/hybrid architectures can add fixed per-sequence state. The formula for each architecture is specified in the "Follow the calculation" section

2. Caching saves compute costs by spending memory

If you throw the prefix away, you eventually have to prefill it again:

t_recompute ≈ (2 N_seq L P_active) / F_cluster

The key idea: the economic value of cached state is bounded by the cost of recreating it.

3. Cache duration has a storage cost

C_rent(T) = M_cache · r_tier · T

This is the thing I most want explained because it makes the TTL chart immediately legible: recomputation is basically fixed for a given workload; storage costs generally rise linearly with cache duration.

4. Offloading to disk trades cheaper capacity for slower retrieval

t_restore = M_cache / BW_tier

and

E[C_cache] = C_rent + h C_restore + (1 − h) C_recompute

DDR/SSD/HDD gives you lower storage cost while consuming more serving time when the cache is actually reused.

5. The break-even TTL falls directly out of the inequality

Start with:

C_rent + h C_restore + (1 − h) C_recompute < C_recompute

Rearrange:

C_rent < h(C_recompute − C_restore)

And because (C_rent = M r T):

T* = h(C_recompute − C_restore) / (M_cache r_tier)

This is the core predictive lens of the explainer. It tells you directly why longer TTLs, larger caches, expensive storage, low hit rates, and slow retrieval each push you toward recomputation.

The general decision rule:

s* = arg min_{s ∈ {HBM, DDR, SSD, HDD, recompute}} E[C_s]

Methodology & assumptions

Storage profiles

DDR starts at 512 GB and 100 GB/s, SSD at 4,096 GB and 6 GB/s, HDD at 16,384 GB and 0.2 GB/s. Capacity and rent are configurable in the advanced assumptions.

Recomputation

Prefill recomputation is approximated as 2 × cached tokens × active parameters. This captures the dominant linear model work but excludes quadratic attention costs, so recomputation may be understated at long context lengths. Future iterations will add architecture-aware computation costs. Cost is derived from peak selected compute and pro-rated cluster rent.

Storage allocation

Rent is allocated linearly by the cache's share of tier capacity. Reserved capacity, replication, metadata, and allocator fragmentation are excluded.

Hits, misses, and retrieval

A hit pays retrieval opportunity cost; a miss pays recomputation. The selected hit rate weights both paths. Retrieval represents blocked hardware time, not a cloud egress invoice.

Cluster sizing

Model weights and KV state must fit in HBM. Accelerator count rounds up to the next power of two to mirror common tensor-parallel layouts.

Implementation sources

Educational estimator only. Production costs depend on utilization, topology, transfer overlap, cache hit probability, replication, and provider pricing.