Inference Engineering interview question · PagedAttention and prefix caching · mid level
What is PagedAttention?
Free to read in full. This is 1 of the 120 questions in the Inference Engineering interview pack, with 141 diagrams. Get the pack, ₹999 · $20
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.

The answer
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
- Confusing it with CPU paging to disk
Written by Roni Das, who builds distributed systems and AI systems for a living.
Learn it properly
This is taught step by step in the course lesson LLM Inference Optimization: Serving More Tokens Per GPU.
One question is not enough for the interview.
This is 1 of the 120 questions in the Inference Engineering pack
Each question has why it is asked, a full answer, what the interviewer listens for, the follow-ups, the common mistakes and a diagram (141 diagrams in all). A PDF you keep, junior to staff level.
India: UPI, cards or netbanking through Razorpay. Elsewhere: PayPal. Download at once from My packs.
More free questions from this pack
Free questions from the other packs
- What do temperature and top-p control, and what values would you use for data extraction versus brainstorming? (AI Engineering)
- What is hybrid search, and how do you merge keyword and vector results with Reciprocal Rank Fusion? (AI Engineering)
- Users ask "list all X" questions and RAG returns only five items. Why, and what do you do? (AI Engineering)
- How do you check that an LLM judge agrees with human reviewers? (AI Engineering)
- Cut the cost of an LLM feature serving 10 million requests a day by 60% without hurting quality. Walk through your plan. (AI Engineering)
- Why are LLMs bad at counting letters or reversing a word? (GenAI and LLM)
- Write out scaled dot-product attention with the shape of every tensor. (GenAI and LLM)
- How does speculative sampling keep exactly the target model's distribution? (GenAI and LLM)
- What is GRPO, and how do verifiable rewards train reasoning models? (GenAI and LLM)
- Design a system that answers questions from 300-page contracts accurately. (GenAI and LLM)
- Compute the cosine similarity of a = (3, 4) and b = (4, 3) by hand. What does the result mean? (Maths for ML)
- A batch of 32 MNIST images goes into a dense layer with 128 units. What are the shapes, and what is the rule for when two matrices can be multiplied? (Maths for ML)
- A disease affects 1% of people. A test catches 90% of sick people (sensitivity) and wrongly flags 9% of healthy people (false positive rate). You test positive. What is the chance you are sick? (Maths for ML)
- Why do we not use mean squared error for classification with a sigmoid output? Compare the gradients numerically. (Maths for ML)
- Compute scaled dot-product attention by hand for two tokens with d_k = 2. (Maths for ML)
- A customer says: "We want AI for our support team." What do you do in the first meeting? (Forward Deployed Engineer)
- The customer's admin offers you a global admin account "to save time". What do you ask for instead, and why? (Forward Deployed Engineer)
- Your connector writes tickets into the customer's system. A request timed out, the connector retried, and now there are duplicate tickets. How do you make the writes safe to retry? (Forward Deployed Engineer)
- The customer wants RAG over 10 million documents, all behind their firewall. Size it for me on the whiteboard. (Forward Deployed Engineer)
- One deployment of your AI platform must serve 50 business units of the same enterprise. How do you design multi-tenancy? (Forward Deployed Engineer)
