Zenaique

Prefix cache hit lands on a request: does speculative decoding still help that request?

Short answer·Medium·4.0 · 0·~3 min·Asked atAi21AirbnbBraintrust·Relevant atNVIDIA
Attempt it

Explain how a prefix cache hit changes the latency profile of a request, and whether that change makes speculative decoding more, less, or equally valuable for the same request. Argue from where each technique actually saves time.

Free · 2 AI evals / day
TL;DR

Prefix cache saves prefill, speculation saves decode. They are orthogonal, and speculation's relative win on a cache-hit request is unchanged. The two stack and you want both for long-prefix RAG.

Memory aid
Sign in to see the mnemonic that makes this stick.
Easy to grasp

Think of a long bus trip in two parts: a slow scenic drive to the city (prefill), then a fast highway run home (decode). A prefix cache is like a teleporter that skips the scenic drive when you have made the same trip before; it has nothing to do with how fast the highway part goes. Speculative decoding is a faster engine for the highway run; it has nothing to do with whether you teleported there or drove. If you teleport in and then drive home, the faster engine still gives you the same time savings on the highway as it would after a normal scenic drive. The two improvements affect different legs of the same trip, so they stack rather than overlap.

Concept explanation~2 min read

Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.

Speculative decoding and prefix caching are the two highest-impact serving optimizations of the modern LLM stack. They sometimes get conflated because both reduce request latency and both depend on workload shape. They are actually independent in mechanism, in math, and in the way they should be monitored.

This question tests whether you can decompose a request into its two phases, attribute each optimization to the correct phase, and reason about composition rather than overlap. A strong answer treats them as orthogonal and concludes that the relative value of speculation is unchanged by a cache hit.

The deep dive walks the phase decomposition, the mechanism of each optimization, the math of speculation's speedup factor, and the operational consequences for tuning and monitoring.

Decomposing a request into prefill and decode

An LLM request has two phases with different bottlenecks. Prefill processes the entire prompt in one parallel forward pass. Attention is computed over all prompt tokens simultaneously, which is a large matmul that is compute bound. Throughput scales with FLOPs.

Decode generates one token at a time. Each step reads the entire KV cache for the sequence from HBM, computes attention against it, samples one new token, and writes one new token's worth of KV back. The matmul on a single token is tiny relative to the HBM read of the full weights, so decode is memory bandwidth bound. Throughput scales with HBM bytes per second.

Total request latency is T_prefill + T_decode. On RAG with long retrieved context and medium completion, prefill might be 70 percent of the time on a cache miss and decode 30 percent. On chat with short prompts and longer replies, the ratio inverts.

The two phases are bottlenecked on different resources, respond to different optimizations, and should be monitored separately.

What prefix caching does
What speculative decoding does
Composition, monitoring, and operational posture
Sign in to unlock the full deep dive.

Situations where this technique stops working.

Sign in to see when this approach fails.

2–4 min · Everything important, quickly.

Sign in to see the quick scan of the deep dive.

Real products, models, and research that use this idea.

  • vLLM v1 ships prefix caching and speculative decoding as independent flags; the docs explicitly recommend enabling both for RAG workloads.
  • Anthropic's prompt caching (Claude Opus 4.7, Sonnet 4.6) sits on top of internal speculative decoding; the documented latency improvements are additive on long-prompt routes.
Sign in to see more production examples.

What an interviewer would ask next. Try answering before peeking at the approach.

QWhat is the formal speedup formula for speculative decoding, and which terms matter most?
A

Speedup roughly equals 1/(1α+cdraft/ctarget)1 / (1 - \alpha + c_{draft}/c_{target}) where α\alpha is acceptance rate and cc are per-step costs of draft and target. Acceptance rate dominates in practice; drafts with α>0.7\alpha > 0.7 give meaningful speedups while drafts with α<0.5\alpha < 0.5 rarely pay back the draft-model cost.

2 more follow-ups an interviewer would ask next. Sign in to reveal them.

Red flags & common mistakes

The phrases that signal junior thinking. Click to expand.

Most common mistake

Assuming that a cache hit reduces the value of speculation because total request time is shorter. The relative speedup of speculation is set by decode-step cost and acceptance rate, neither of which the cache touches.

Sign in to see all red flags and common mistakes.

60 second bullets to scan on the way to the call.

  • Which phase prefix cache reduces and which it leaves alone

  • Which phase speculative decoding reduces and the math of its speedup

Sign in to unlock the revision sheet.

Primary sources. Browse if you want the original framing.

Similar questions

Same topic, related formats. Practice these next.

4 curated
Next question
What is the KV cache in transformer inference?
Flashcard·Easy