Lifeline diagram of one request moving from client to API server, scheduler and GPU worker through prefill and a streamed decode loop.
Why it is asked: Checks that you know the full path of a request, not only the model call, and can say where time and memory go.
A request goes through tokenize, queue, prefill, a decode loop, and cleanup.
- The API server receives the HTTP request, checks auth and limits, applies the chat template (the fixed text format the model was trained on) and turns the text into token ids.
- The scheduler puts the request in a queue. It admits it into the running batch when there is free GPU memory for its KV cache (the stored keys and values of earlier tokens).
- Prefill: the GPU runs the whole prompt through the model in one forward pass. This writes the KV cache for every prompt token and gives the logits (scores over the vocabulary) for the first output token.
- A sampler picks the token: greedy (always the top token), or temperature and top-p (settings that add controlled randomness), and the detokenizer turns it into text that is streamed back.
- Decode loop: each step feeds the last token back in, reads all weights plus this request's KV cache, and produces one more token. Other requests share the same step through batching.
- It stops on an end-of-sequence token, a stop string or max_tokens. The server frees the KV blocks and returns usage counts.
For scale (each number is explained in later questions), take Llama 3 8B in BF16 (2 bytes per number) on one H100 (NVIDIA's data-center GPU). A 1,000-token prompt needs about 1.6 x 10^13 (about 16 trillion) FLOPs (arithmetic operations), about 32 ms of prefill at 50% of peak compute. Each decode step reads 16 GB of weights, at least 4.8 ms, so 300 output tokens take about 1.4 s. The KV cache for 1,300 tokens is about 0.17 GB.
What the interviewer listens for
Tokenize with the chat template before anything reaches the GPU
Admission depends on free KV cache memory, not only on a queue slot
Prefill builds the KV cache and gives the first token in one pass
Decode adds one token per step and shares each step with other requests
Stop conditions and freeing KV blocks are part of the lifecycle
Follow-ups the interviewer may ask
Where does most of the wall-clock time go for a long answer? Hint: the decode loop, one memory-bound step per token.
What happens if the client disconnects mid-answer? Hint: the server should abort the sequence and free its KV blocks at once.
Where can prefix caching help? Hint: it skips prefill for a shared prompt start that is already in the KV cache.
Common mistakes
Describing the model as producing the whole answer in one pass
Forgetting tokenization, sampling and detokenization, which can add real CPU time
Ignoring the queue, which is often the biggest part of time to first token under load
Hand-drawn matrices showing per-layer K and V caches of n by 1,024 values, then the arithmetic 2 x 80 x 8 x 128 x 2 = 327,680 bytes per token and 1.34 GB for 4,096 tokens.
Why it is asked: Every capacity plan starts with this formula. The interviewer checks each factor and that you use KV heads, not query heads.
KV bytes per token = 2 x layers x KV heads x head dimension x bytes per value, which for Llama 3 70B in BF16 (2 bytes per number) is 2 x 80 x 8 x 128 x 2 = 327,680 bytes, about 0.33 MB per token.
Where each factor comes from:
- 2: one key vector and one value vector are stored.
- layers: every transformer layer has its own attention, so its own K and V. Llama 3 70B has 80.
- KV heads: the number of key-value heads, not query heads. Llama 3 70B has 64 query heads but uses grouped-query attention (GQA) with 8 KV heads, each shared by 8 query heads.
- head dimension: the length of each head's vector, 128 here. So each layer stores 8 x 128 = 1,024 values for K and 1,024 for V per token.
- bytes per value: 2 for BF16, 1 for FP8.
Then total KV = bytes per token x tokens per sequence x number of sequences.
For Llama 3 70B:
- 4,096 tokens: about 1.34 GB per sequence.
- 8,192 tokens: about 2.68 GB.
- 16,384 tokens (Llama 3.1 70B, same shape, longer context): about 5.37 GB.
With an FP8 KV cache the figure halves to 163,840 bytes per token. For comparison, Llama 3 8B (32 layers, 8 KV heads) needs 131,072 bytes per token.
Check: if you had used 64 heads instead of 8, you would get about 2.62 MB per token, 8 times too much. This is the most common slip.
What the interviewer listens for
2 x layers x KV heads x head_dim x bytes
Use KV heads (8), not query heads (64)
327,680 bytes per token for Llama 3 70B in BF16
Multiply by tokens and by concurrent sequences
Follow-ups the interviewer may ask
How does tensor parallelism split this? Hint: KV heads are divided across GPUs, so with TP=8 each GPU holds one KV head per layer.
Does the formula hold for DeepSeek-V3? Hint: no; its multi-head latent attention stores a compressed latent, so use its own formula.
Common mistakes
Using the number of query heads
Forgetting the factor 2 for K and V
Mixing GB (10^9 bytes) and GiB (2^30 bytes) in the same calculation
A lookup diagram where four logical blocks of one sequence map through a block table to scattered physical KV blocks in GPU memory.
Why it is asked: PagedAttention is the memory model behind vLLM and most engines since; you should explain it with the operating-system analogy and the block table.
PagedAttention stores each sequence's KV cache in small fixed-size blocks that can sit anywhere in GPU memory, and keeps a block table per sequence that maps its logical blocks to physical blocks, like virtual memory pages in an operating system: like a book's index that points to pages stored anywhere.
It was introduced with vLLM (Kwon et al., SOSP 2023). The default block holds the keys and values of 16 tokens.
How it works:
- When a sequence needs room for more tokens, the engine takes any free physical block and adds an entry to that sequence's block table. Nothing needs to be contiguous.
- The attention kernel reads the block table to find where each part of the sequence's KV lives, then computes attention block by block.
- When the sequence finishes, its blocks go back to the free pool at once.
What it buys:
- Almost no waste: only the last block of each sequence can be partly empty, at most 15 tokens.
- No reservation for the maximum length, so far more sequences fit and batches get bigger.
- Sharing: two sequences can point at the same physical block, which enables prefix caching and parallel sampling (several answers to one prompt) with copy-on-write (copy a shared block only when someone needs to change it).
The cost is an indirection inside the attention kernel and engine bookkeeping, which is small next to the memory saved.
What the interviewer listens for
KV split into fixed blocks (16 tokens by default in vLLM)
A per-sequence block table maps logical blocks to any physical block
Waste limited to the last partial block
Enables sharing: prefix caching and copy-on-write
Follow-ups the interviewer may ask
What happens when no free block is left? Hint: the scheduler preempts a sequence, then swaps or recomputes it later.
Why does attention need a special kernel? Hint: it must gather keys and values from non-contiguous blocks using the table.
Common mistakes
Saying PagedAttention makes the attention math cheaper; it changes memory layout, not FLOPs
A line chart of speculative decoding speedup against batch size for an 8B model on one H100, flat at 2.80x up to batch 32 and falling below 1.0 near batch 187 for acceptance 0.8, and earlier for acceptance 0.6.
Why it is asked: Speculative decoding is often switched on blindly. The interviewer checks that you know it spends idle GPU compute, and that the idle compute disappears at high batch or low acceptance.
Speculative decoding stops helping when the GPU is no longer idle during a normal decode step: at large batch sizes, with a low acceptance rate (the chance each draft token is accepted), or with a draft that costs too much. Past that point it makes each token slower.
Why it works at all: at small batch a decode step is memory-bound, limited by reading the weights from HBM (the GPU's main memory), so checking 5 tokens costs about the same as producing 1. Speculation spends that spare compute.
Where it breaks:
- Large batch. In a simple roofline model of an 8B target on one H100 (BF16, acceptance 0.8, 4 draft tokens, draft cost 5% of a target step), the speedup is 2.80x from batch 1 to 32, 2.62x at 64, 1.42x at 128 and 0.74x at 256. Each sequence sends 5 tokens to the target, so verification turns compute-bound near batch 59 (295 / 5). Break-even is near batch 187.
- Low acceptance: high-temperature sampling, creative text, or a draft from a different domain. At batch 1, acceptance 0.3 gives only 1.19x; with a heavier draft costing a quarter of a target step per drafted token, it is 0.71x, a slowdown.
- Hidden costs: rejected tokens are wasted compute, and a draft model's weights and KV cache take memory that would otherwise hold a bigger batch.
What to measure: acceptance rate per traffic type, speedup against batch size on your hardware, TPOT (time per output token) p50 and p99, and goodput. Then switch it off, or shorten the draft, above a measured batch threshold.
What the interviewer listens for
It spends spare compute that exists only while decode is memory-bound
Model: 2.80x up to batch 32, 1.42x at 128, 0.74x at 256
Low acceptance or an expensive draft can make it slower even at batch 1
Draft memory reduces KV room and so maximum batch
Gate it by measured batch size and acceptance rate
Follow-ups the interviewer may ask
Why does the curve fall near batch 59 and not 295? Hint: each sequence verifies 5 tokens, so the target processes 5 times the tokens per step.
Does speculation help time to first token? Hint: no, it only speeds up decode; the draft also has to process the prompt.
How would you adapt it at runtime? Hint: shorten the draft or turn it off as the running batch grows.
Common mistakes
Benchmarking at batch 1 and enabling it for a busy multi-tenant endpoint
Ignoring the draft's own memory and KV cache
Assuming acceptance measured on one dataset holds for all traffic
An architecture with web and API clients, an Envoy gateway and token-aware router, two TP=4 FP8 replicas of Llama 3 70B on separate nodes with a shared weight store, and Prometheus, Grafana and a load tester for monitoring.
Why it is asked: This is the classic staff inference design question. The interviewer wants the binding constraint found first, Little's law applied with the real step time, memory and compute checked, and redundancy that survives a node loss.
One TP=4 replica of Llama 3 70B in FP8 on 4 H100s carries 10 QPS with room to spare; I deploy two, on separate nodes, for N+1 redundancy.
Requirements: 10 QPS, 1,000 in and 300 out, TTFT under 1 s, TPOT (time per output token) at most 40 ms.
Sizing, binding constraint first (ideal model at an assumed 50% of FP8 peak; 'real' assumes kernels take 1.6x the ideal step):
- Prefill: 36 ms per 1,000-token prompt. At 10 QPS it takes 36% of GPU time, and prefill alone would saturate the replica near 27.8 QPS: the workload is prefill-heavy.
- Decode: each step reads 70.6 GB of weights plus the KV cache. At 10 QPS, TPOT is about 9.5 ms ideal, 16.8 ms real.
- Little's law (requests in the system = arrival rate x time each spends inside), with the real step, not the SLO: in flight = 10 x (TTFT + 299 x TPOT), about 29 sequences ideal, 51 real.
- Memory: 21.7 GB of KV at the real point; 92 of 320 GB used.
- Capacity: TPOT reaches 40 ms near 19.5 QPS ideal, 15.9 real. The 40 ms target is headroom, not the operating point.
So one replica runs at about 63% of real capacity. Two replicas on different nodes survive a node failure: $20/h at an assumed $2.50 per GPU-hour, about $1.85 per 1M output tokens.
Architecture: an Envoy gateway (auth, quotas, fast 429 'too many requests' errors), a least-pending-tokens router, vLLM or TensorRT-LLM with chunked prefill.
FP8 needs evals.
Measure in Prometheus and Grafana: p95 TTFT and TPOT, queue time, KV usage; load-test the real capacity.
What the interviewer listens for
Find the binding constraint: prefill takes 36% of the replica at 10 QPS
Little's law with the real step (9.5 to 16.8 ms), not the 40 ms SLO: 29 to 51 in flight
70.6 GB FP8 weights + about 22 GB KV fits easily in 320 GB
Capacity about 15.9 QPS real per replica; deploy two in separate failure domains
Continuous batching, chunked prefill, admission control, FP8 evals, load test
Follow-ups the interviewer may ask
Could TP=2 work? Hint: memory yes (35.3 GB of weights per GPU plus KV), but prefill would take 72% of its compute and real capacity falls to about 5.8 QPS.
What if outputs grow to 1,000 tokens? Hint: decode work and time in system roughly triple; recompute capacity and KV before adding replicas.
Why chunked prefill? Hint: a long prompt's prefill otherwise blocks everyone's decode steps and breaks TPOT.
Common mistakes
Using the 40 ms TPOT target as the step time in Little's law
Forgetting that prefill compute, not memory, binds this workload
Putting both replicas on one node and calling it redundant
GPU memory, KV cache, batching, quantization, speculative decoding, parallelism and cost per token.
120 questions and 141 diagrams, each with why it is asked, a full answer, what the interviewer listens for, follow-ups, common mistakes and a diagram. By Roni Das.