Inference engineering: interview drills

  • Production
  • 40 min
  • Lesson 7 of 7 in Inference engineering
  • Last verified

Open slides(32 slides)

Before you start

You will be able to

  • Explain the core serving ideas (prefill and decode, the KV-cache, batching with paging, quantization, speculative decoding, the levers for TTFT and inter-token latency) clearly in about 90 seconds each.
  • Work the standard derivations: the batch-1 decode bound, KV bytes and concurrency, the speculative-decoding speedup, cost per million tokens with utilization, and replicas from peak load.
  • Structure a 40-minute inference-platform design answer in seven parts and name the markers of a strong one.
  • Diagnose a described serving symptom by phase and cause, and propose a fix together with its price.

An email arrives from management. One line: the model is to be twice its current size, and a serving plan is due in forty minutes.

Ananya lays a sheet of paper over the dashboards. “You may not measure anything,” she says. “Only work it out.”

Where do you start?

Concept

This lesson turns the module into practice. Every answer below can be built from lessons 1 to 6; the point is to say it aloud, under a clock, in a structure an interviewer can follow. Use it in this order: answer a prompt aloud first, then open the key. A drill you only read teaches little.

The questions are Common industry pattern or Generated practice, and none is verified as asked by a named company. Sample answers are one good answer, not the only one. Numbers marked illustrative are invented to make arithmetic concrete.

Why It Matters

Knowing the ideas is not the same as deriving a number at a whiteboard or designing a platform in forty minutes. Serving interviews tend to probe the same few things: whether you start from bytes and FLOPs, whether you separate the two phases, whether you put numbers on every claim, and whether you raise failure modes before you are asked. Rehearsing each in turn exposes gaps that reading hides.

Mental Model

Ananya’s paper over the dashboards is the exercise. You predict from the model’s size, the hardware’s datasheet and the traffic’s shape, and you say what you would measure to confirm. A strong answer goes in a fixed order, because order keeps you calm and lets the listener follow: clarify the targets, estimate, choose the stack, draw the architecture, plan evaluation and rollout, name failure modes, then cost and trade-offs.

Diagram: A strong answer goes in a fixed order of seven steps: clarify the targets, estimate from the model’s size, the datasheet and the traffic,...

1 Clarify the targets

2 Estimate

3 Choose the stack

4 Draw the architecture

5 Plan evaluation and rollout

6 Name failure modes

7 Cost and trade-offs

Diagram summary: A strong answer goes in a fixed order of seven steps: clarify the targets, estimate from the model’s size, the datasheet and the traffic, choose the stack, draw the architecture, plan evaluation and rollout, name the failure modes, then cost and trade-offs.

Ninety-second explanations

Rehearse until each fits in about ninety seconds, with one number and one trade-off.

  1. Prefill versus decode, and why decode is memory-bound. Prefill processes the prompt in parallel and sets TTFT; decode produces a token per step, reads all weights each step, and its intensity is about the batch size, far below the ridge. (Lesson 1.)
  2. The KV-cache: what, how big, what limits concurrency. Keys and values of past tokens; 2×layers×KV heads×head dimension×bytes2 \times \text{layers} \times \text{KV heads} \times \text{head dimension} \times \text{bytes} per token; the pool left after weights and overhead divided by bytes per sequence. (Lesson 2.)
  3. Continuous batching with PagedAttention. The batch is re-formed every step; blocks are allocated on demand, so waste is at most part of one block. It raises batch size; it does not shrink bytes or speed attention. (Lessons 2 and 4.)
  4. Quantization: what, which kind when, how to validate. Weight-only for memory-bound decode, W8A8 or FP8 for compute-bound work, task evaluations against the baseline, a canary. (Lesson 3.)
  5. Speculative decoding: why lossless, when it helps. Draft, verify in one pass, accept or resample; low-concurrency, memory-bound serving; gains shrink at high batch or low acceptance. (Lesson 4.)
  6. TTFT versus inter-token latency, and the levers for each. TTFT: queueing, prefill length, prefix caching, chunked prefill, capacity. ITL: bytes per step, batch and context size, quantization, speculative decoding, parallelism. (Lessons 1 to 5.)

Whiteboard derivations

Try each before reading the key. State assumptions aloud.

  • B1. Batch-1 decode lower bound for a 14B model stored in 8-bit on a GPU with 1.5 TB/s of bandwidth.
  • B2. KV bytes per token for 40 layers, 8 KV heads, head dimension 128, FP8; then concurrency for a 30 GB cache pool and 4,096-token sequences.
  • B3. Speculative-decoding speedup for α=0.85\alpha = 0.85, γ=5\gamma = 5 and c=0.08c = 0.08.
  • B4. Cost per million tokens: 2.80 dollars per hour, 2,200 tokens per second at full load, 50 percent utilization.
  • B5. Replicas for a peak of 18 requests per second at 300 output tokens each, with 1,500 output tokens per second per replica at the target, 0.65 target utilization and one spare.

Key.

  • B1: 14 GB÷1.5 TB/s=9.3 ms14\ \text{GB} \div 1.5\ \text{TB/s} = 9.3\ \text{ms} per step, so at most about 107 tokens per second. It ignores the KV read, communication and overhead.
  • B2: 2×40×8×128×1=81,9202 \times 40 \times 8 \times 128 \times 1 = 81{,}920 bytes (80 KiB) per token. A 4,096-token sequence is 335,544,320 bytes (about 0.34 GB), so 30 GB holds about 89 sequences.
  • B3: Expected tokens per step =(1−0.856)÷0.15=4.15= (1 - 0.85^{6}) \div 0.15 = 4.15. Speedup =4.15÷(5×0.08+1)=4.15÷1.4≈2.97= 4.15 \div (5 \times 0.08 + 1) = 4.15 \div 1.4 \approx 2.97.
  • B4: Effective throughput 1,100 tokens per second. $2.80÷(1,100×3,600)×106≈$0.71\$2.80 \div (1{,}100 \times 3{,}600) \times 10^{6} \approx \$0.71 per million, twice the 0.35 at full load.
  • B5: Peak output = 5,400 tokens per second. 5,400÷(1,500×0.65)=5.55{,}400 \div (1{,}500 \times 0.65) = 5.5, so 6 serving replicas, plus one spare: 7. Cross-check concurrency with Little’s law against the cache pool.

Design drill 1: a shared inference platform (40 minutes)

Prompt. Serve three internal products on one GPU fleet: a chat assistant, document question answering, and a nightly batch summarization job. About 2,000 concurrent chat users at peak, a mix of 8B and 70B models, strict data residency (no external APIs).

A framework to say aloud.

  1. Clarify. Targets per class (TTFT and ITL for chat, completion window for batch), token distributions, peak rate, quality bar, availability target, budget.
  2. Estimate. Use Little’s law. If each of the 2,000 users sends a request every 60 seconds and a request takes 8 seconds, arrivals are 33 per second and about 267 requests are in flight. For a 70B model with 8-bit weights on two 80 GB GPUs, the cache budget is about 66 GB, which at 320 KiB per token is about 200,000 tokens, or about 67 sequences of 3,000 tokens (lessons 2 and 5). So the cache alone asks for about 4 replicas; throughput capacity from a benchmark may ask for more.
  3. Stack. An engine such as vLLM or SGLang, 8-bit or 4-bit weights validated on your evaluations, tensor parallelism within a node and replicas for volume, prefix caching for shared prompts, chunked prefill and priorities.
  4. Architecture. Gateway with quotas, a router (prefix-aware, least loaded, priority), an interactive pool and a batch pool, observability, an autoscaler on queue depth and cache usage, and a weights store with node caches.
  5. Evaluation and rollout. Offline evaluations, shadow traffic, canary, automatic rollback, and an evaluation gate for every quantization or model change.
  6. Failure modes and operations. Out-of-memory on long inputs, preemption storms, GPU faults, cold start, noisy neighbours, deploy herds, and what happens to a stream when a replica dies.
  7. Cost and trade-offs. Utilization targets, off-peak or interruptible capacity for batch, routing easy requests to the small model, and what you would cut first.
Diagram: Users reach a gateway and a router that sends interactive traffic to 8B and 70B pools and batch traffic to its own pool.

Users and services

Gateway: authentication, quotas

Router: priority, prefix affinity, least loaded

Interactive pool: 8B, replicas

Interactive pool: 70B, 8-bit weights, tensor parallel 2, replicas

Batch pool: 70B, large batches, off-peak

Metrics and traces

Autoscaler: queue and cache signals

Diagram summary: Users reach a gateway and a router that sends interactive traffic to 8B and 70B pools and batch traffic to its own pool. All pools emit metrics, and an autoscaler adds or removes replicas using queue and cache signals.

Markers of a strong answer. Numbers with stated assumptions; interactive and batch separated; the KV arithmetic drives concurrency; autoscaling on queue depth and cache, not GPU utilization; a cold-start plan; a quality gate for quantization; what happens when a replica dies mid-stream; cost per million tokens at a realistic utilization. Expect the interviewer to change a constraint (“traffic is five times higher”, “the TTFT target halves”, “the model doubles in size”). Re-cost the design aloud and say what you would give up.

Design drill 2: a model twice the size (30 minutes)

Key points. Weights double: a 70B model in 8 bits is 70 GB; a 140B model is 140 GB, so a pair of 80 GB GPUs no longer leaves room for the cache and you need at least four, or lower-bit weights. The step floor falls with more bandwidth but rises with bytes, and the cache per token grows with layers and KV heads (compute it from the configuration). Tensor parallelism within a node, replicas for volume. Re-validate quality after any new quantization. Re-benchmark open-loop on your own traffic, since neither throughput nor latency scales with parameter count in a simple way. Re-plan capacity, and re-check cold start, because 140 GB of weights load more slowly than 70. Say what you would measure first on real hardware to confirm.

Rapid-fire

Answer each in about twenty seconds.

  1. Why does batching raise throughput without hurting latency at first?
  2. What does the number of KV heads have to do with serving cost?
  3. Why can you not add GPUs with tensor parallelism forever?
  4. Prompt caching versus semantic caching?
  5. When does speculative decoding backfire?
  6. Why is p99 TTFT worse than p50 for chat traffic?
  7. What must an LLM replica’s health check do?
  8. Why is temperature 0 not deterministic?
  9. FlashAttention: approximate or exact?
  10. What do you scale on, and what do you not scale on?

Key. 1. Weight reads are shared across the batch while the arithmetic was idle, so it stays memory-bound until the ridge or the cache limits. 2. Cache bytes per token scale with KV heads, so they set concurrency. 3. All-reduces inside every layer add communication that grows with the degree, and links limit it; quantize or replicate instead. 4. Prompt caching reuses prefill for identical leading tokens; semantic caching returns stored answers for similar queries. 5. At large batch (no idle arithmetic), with low acceptance, or when the draft costs too much. 6. Queueing, long prompts, preemption, cold replicas and prefix-cache misses hit a tail of requests. 7. Generate a token end to end through the GPU and engine. 8. Floating-point addition is not associative and reduction order depends on batch and kernels. 9. Exact. 10. Queue depth, cache utilization and TTFT; not CPU or GPU utilization alone.

Diagram: Start every scenario by naming the symptom.

Slow first token

Slow or stuttering stream

High cost, flat traffic

Quality dropped after a speedup

Out of memory or utilization high but goodput low

A serving symptom

Which one?

Queueing, long prompts, prefix hit rate, prefill interference

Batch or context growth, big prefills, bandwidth, throttling

Tokens per request, prefix hit rate, routing, utilization

Quantization or kernel change: task evals against the baseline

KV cache arithmetic, preemption count, concurrency cap

Diagram summary: Start every scenario by naming the symptom. Slow first tokens point to queueing and prefill, a stuttering stream to decode pressure, rising cost to tokens or cache misses, a quality drop to a recent optimisation, and memory trouble to the KV cache arithmetic and preemption.

Scenario drills

Diagnose each aloud before reading the answer.

  • E1. “After deploying a 4-bit build, throughput rose 30 percent and tickets about wrong tool arguments doubled.” An average hides a capability regression. Run task evaluations on tool-call accuracy and JSON validity against the 16-bit baseline, slice by tool, consider 8-bit or mixed precision for sensitive layers, canary and keep a rollback.
  • E2. “Streaming stutters whenever someone pastes a huge document.” Prefill interference. Enable and tune chunked prefill and the token budget, cap input size, isolate long-prompt traffic, and consider disaggregation only at scale.
  • E3. “GPU utilization is 90 percent but throughput dropped.” Likely preemption and recompute with a full cache. Check the preemption count, cache utilization and batch composition; cap concurrency or context, quantize the cache, add replicas.
  • E4. “Costs doubled with flat traffic.” Tokens per request grew (a prompt change, longer reasoning), the prefix hit rate fell (dynamic content moved to the front), a routing change, or lower utilization after a scaling change. Compare each against a baseline.
  • E5. “A 128k-context feature runs replicas out of memory.” Cache arithmetic: one 128,000-token sequence on the 70B model is about 39 GiB. Cap and tier context, consider an 8-bit cache once quality is validated at long lengths, use chunked prefill, send long contexts to a dedicated pool, and prefer retrieval to stuffing.
  • E6. “Self-hosted p95 TTFT was fine in the benchmark and is four times worse in production.” The benchmark used fixed short prompts, closed-loop clients and a hot cache. Replay real traces with open-loop arrivals and control the cache.

Real-World Application

Run a mock with a friend as the interviewer who may only ask, not teach. A 35-minute version: three explanations from the first list, one derivation, one scenario. A 45-minute version: design drill 1 with the interviewer changing a constraint twice. Afterwards write down the two places you lost the thread and the lesson that covers each, and repeat those drills a few days later on a nearby variant, such as drill 1 for a service that is mostly long-context retrieval.

Interview Perspective

Expect all of the above in any order. The signals interviewers tend to look for are structure under time pressure, derivations with stated assumptions, separation of the two phases, numbers for cost and capacity, and failure modes raised without being asked. A common failure is to name tools without saying what each costs or which bottleneck it attacks.

Provenance: Common industry pattern and Generated practice. None of these drills is verified as asked by a named company.

Practice Questions

  • Basic: Give the 90-second answer to “Why is decode memory-bound?” with one number.
  • Intermediate: Work B2 again for 60 layers, 8 KV heads, head dimension 128 in FP8, and a 24 GB pool with 8,192-token sequences.
  • Advanced: Run design drill 1 with the constraint “all traffic is long-context document analysis”. What changes?
  • Product-Company: Design a serving plan for a model twice the size of the one you run today, in 40 minutes, without access to measurements.

Activity

Time yourself on one explanation and one derivation. If either takes more than twice its budget, mark the lesson it comes from and read that section again, then try a nearby variant rather than the same prompt.

Homework

Record yourself answering design drill 2 in 30 minutes. Play it back and list the points from the key you missed, then rewrite your opening 60 seconds so that it states the targets you are optimising and the order you will cover things.

Quick Revision

  • Explain each core idea in 90 seconds with one number and one trade-off.
  • Know the derivations: batch-1 bound, KV bytes and concurrency, speculative speedup, cost per million tokens with utilization, replicas with Little’s law.
  • Design in seven parts: clarify, estimate, stack, architecture, evaluation and rollout, failure modes, cost and trade-offs.
  • Diagnose by phase (TTFT or ITL), then by cause, then fix with its price.
  • When a constraint changes, re-cost aloud and say what you give up.

Check yourself

  • Walk-through: Design a serving platform for a chat assistant, document question answering and a nightly batch job in about forty minutes.
  • Variation: Redo it for a model twice the size, without measurements.
  • Common misconception: “More optimizations make a better design.” Each one should attack a measured or computed bottleneck and have a stated cost.

Resources & Further Reading

Checked sources to go deeper. The essential ones come first in each group.

Further reading

Hands-on

More for this module: Inference engineering resources

Practice

Test what you just read. Quizzes and cards are grouped by module: Inference engineering.

Check yourself14 questions on what this lesson set out to teach

Checking answers needs JavaScript. You can still read every question and option below.

0 of 14 answered

Keyboard: arrow keys move between options. Space or Enter selects the focused option.

ObjectiveExplain the core serving ideas (prefill and decode, the KV-cache, batching with paging, quantization, speculative decoding, the levers for TTFT and inter-token latency) clearly in about 90 seconds each.

  1. Question 1 of 14Asked "why is decode memory-bound?", which opening answer is strongest in ninety seconds?

    Choose one answer.

  2. Question 2 of 14Which is the strongest one-line answer to "what limits how many users one GPU serves"?

    Choose one answer.

  3. Question 3 of 14Users say the first word takes a long time at peak hours, but text streams quickly once it starts. Which lever do you reach for first?

    Choose one answer.

ObjectiveWork the standard derivations: the batch-1 decode bound, KV bytes and concurrency, the speculative-decoding speedup, cost per million tokens with utilization, and replicas from peak load.

  1. Question 4 of 14A 24B model stored in 8-bit runs on one GPU with 1.2 TB/s of bandwidth. What is the batch-1 decode ceiling, counting only the weights?

    Choose one answer.

  2. Question 5 of 14A model has 32 layers, 4 KV heads, head dimension 128, and a BF16 cache. About how many 8,192-token sequences fit in a 20 GB cache pool?

    Choose one answer.

  3. Question 6 of 14Speculative decoding has acceptance rate α = 0.9, draft length γ = 3 and draft cost ratio c = 0.1. What is the speedup?

    Choose one answer.

  4. Question 7 of 14A GPU costs $3.20 per hour and delivers 1,600 output tokens per second at full load. Real utilization is 40 percent. What is the cost per million output tokens?

    Choose one answer.

  5. Question 8 of 14Peak is 12 requests per second at 400 output tokens each. One replica sustains 1,200 output tokens per second at the target. With 0.6 target utilization and one spare, how many replicas?

    Choose one answer.

ObjectiveStructure a 40-minute inference-platform design answer in seven parts and name the markers of a strong one.

  1. Question 9 of 14In a 40-minute platform design round, which opening is strongest?

    Choose one answer.

  2. Question 10 of 14Which are markers of a strong platform design answer? Select all that apply.

    Choose all that apply.

ObjectiveDiagnose a described serving symptom by phase and cause, and propose a fix together with its price.

  1. Question 11 of 14After switching the KV-cache to 8 bits, summaries of documents under 20,000 tokens look unchanged, but summaries of documents over 50,000 tokens lose details. What is the right response?

    Choose one answer.

  2. Question 12 of 14Every hour on the hour, p99 TTFT triples for about five minutes. A batch job scheduled at the top of each hour runs on the same replicas as the chat traffic. What is the best fix?

    Choose one answer.

  3. Question 13 of 14A team replaces a chat model with a reasoning model. Traffic is flat, but cost and latency per request rise sharply. What most likely changed?

    Choose one answer.

  4. Question 14 of 14A benchmark showed fine p95 TTFT, and production is four times worse. Which differences could explain it? Select all that apply.

    Choose all that apply.