Mid

How do you reduce LLM latency?

How to answer it in an AI engineer interview: what is being tested, a step-by-step framework, a sample answer and the mistakes to avoid.

$19.99 on Gumroad, instant download40% off with code EARLYBF until Nov 3, 11:59 PM PTEARLYBF: 40% off until Nov 3

Smaller start: Score your answers against 50 rubrics, $9. 50 AI engineer questions, one rubric each, PDF on Gumroad.

Practiced one out loud? Paste your answer into the free self-check and get a score in 30 seconds

What the interviewer is testing

Whether you understand the parts of LLM latency and can pick fixes for each, including the user-perceived side.

Answer framework

  1. Measure the parts: time to first token (TTFT), tokens per second, and total time including retrieval and tools.
  2. Stream output so users see progress immediately.
  3. Shorten inputs (less prefill) and outputs (fewer decode steps); output length often dominates.
  4. Use smaller or faster models for simple steps, and prefix caching for repeated prompt parts.
  5. Remove serial steps: run retrieval and tool calls in parallel, and cut unnecessary chain steps.

Sample answer

I split latency into parts before changing anything. Time to first token depends on queueing, network and prefill, which grows with prompt length. Generation time is the number of output tokens divided by decode speed. Around both sit retrieval, re-ranking and tool calls. A trace of a slow request usually shows one dominant part.

For user-facing chat, streaming is the first fix, because perceived latency is mostly time to first token. Then I cut output length, since each output token is a sequential decode step: ask for concise answers, set max tokens, and avoid generating long reasoning the user never sees. Shorter prompts help prefill, and prefix caching makes repeated system prompts and documents nearly free.

Next is architecture. I use small fast models for routing, classification and extraction, and reserve large models for the final answer. Independent steps such as retrieval from two sources or several tool calls run in parallel rather than one after another. On self-hosted models, quantization and speculative decoding can raise tokens per second. I track p50 and p95 separately, because tail latency is what users complain about.

Likely follow-ups

Why does output length matter more than input length? Prompt tokens are processed in parallel during prefill, while output tokens are generated one at a time.

Common mistakes

The PlaybookWant the full method?

The 0 to 1 AI Engineer Interview Playbook covers the answer frameworks, system-design walkthroughs and an 8-week plan.

Get the playbook 40% off with code EARLYBF until Nov 3, 11:59 PM PTEARLYBF: 40% off until Nov 3

Smaller start: Score your answers against 50 rubrics, $9. 50 AI engineer questions, one rubric each, PDF on Gumroad.

Interviewing for PM or TPM? See the full PM package, $59 on Gumroad: a resume system, a PM, TPM and PGM interview handbook, a 1:1 cheat sheet and a PM playbook. PM and TPM content, not AI engineer prep.

Related questions

Based on question #85 in the full question bank.