Skip to main content

Tokens, context windows, KV cache and TTFT vs TPOT

Explain what happens during prefill vs decode, why prompt caching cuts latency/cost, and how context size affects quality.

Official Reference

Model Answer & Explanation

Prefill processes all input tokens in parallel to build KV cache entries and emit the first token (determining Time-to-First-Token, TTFT). Decode generates one token at a time using cached keys/values (Time-per-Output-Token, TPOT). Reusing a static system/document prefix hits provider prompt cache, slashing TTFT and input token costs. Longer contexts can degrade needle-in-a-haystack recall.

Follow-up Interview Question · Why should dynamic variables (user query, timestamp) go at the end of a prompt instead of the top?

Module Context & References

Applied AI & RAG · Popular interview theory Widely asked LLM, retrieval, grounding, agent and evaluation questions
Personal Notes · Markdown

Technologies & Interview Topics Covered

Switch between short-term interview tracks and long-term 80/20 engineering depth to practice JavaScript internals, React rendering and hooks, timed frontend machine coding UI challenges, MeetaPro FG300, Blind 75 & NeetCode 150 DSA patterns, Python & FastAPI APIs, PostgreSQL query optimization & MVCC, Redis caching, Applied AI RAG pipelines & evaluations, and distributed system design.