Prefill, Decode, TTFT and KV Cache
In this article
- Split one served request into queue, prefill and decode, and compute time per output token.
- Explain why a KV cache removes repeated work in decode, and what it costs in memory as sequences and concurrent requests grow.
- Pair each serving setting that moves first-token latency, streaming speed or cache room with its trade-off.
- Explain how prefix caching reuses blocks, why a shared deployment needs a per-tenant `cache_salt`, and what a faster non-cryptographic hash trades against collision risk.
- Terms defined here: queue time, time per output token, memory-bound, preemption, chunked prefill, step token budget, prefix caching.
Overview
A team runs an open model on its own GPUs with vLLM, and users complain that answers feel slow. The dashboard says requests take 5 seconds. That figure cannot tell a blank screen for four seconds from an instant start followed by crawling text, and those two have different causes and different fixes. Afterwards you can split one request into waiting, reading the prompt and writing the reply, and compute the writing speed from three numbers. You can also say why stored data about earlier words decides how many users one server holds, and which settings trade a faster start against faster streaming.
This article is part of Pro
Pro includes the staff-level and expert articles in every path. It opens after the four core paths are complete.
Still to read in this article
- One request, three intervals
- Prefill, decode and what the KV cache keeps
- Cache memory as the concurrency budget
- Chunked prefill and the token budget
- Prefix caching
- Common mistakes
- In production
- Check yourself
- Sources