Design Prompt Prefix Caching Across a Fleet of Inference Replicas

Last updated: November 29, 2026

Quick Overview

Design a system that reuses attention KV cache for repeated prompt prefixes (long system prompts, shared documents, multi-turn chats) across many GPU replicas, cutting latency and cost for repeated input tokens.

OpenAI
System Design
Machine Learning Engineer
OpenAI
November 29, 2026
Machine Learning Engineer
System Design Round
System Design
Hard

0

0

0 solved


Design a system that reuses attention KV cache for repeated prompt prefixes (long system prompts, shared documents, multi-turn chats) across many GPU replicas, cutting latency and cost for repeated input tokens.

OpenAI offers automatic prompt caching with discounted cached input tokens, and making it effective at fleet scale is mostly a routing and memory-management problem. Interviewers look for understanding of KV cache size, prefix matching granularity, cache-aware load balancing and isolation.

What the Interviewer Expects
  • Explain what is cached (per-layer key and value tensors) and its memory cost
  • Match prefixes at block granularity using hashes of token blocks
  • Route requests to replicas likely to hold the prefix without overloading them
  • Manage eviction across GPU HBM, CPU memory and possibly SSD tiers
  • Isolate caches between organizations and handle model version changes
  • Measure hit rate and its effect on time to first token
Key Topics to Cover
KV cache
consistent hashing
prefix trees
memory tiering
load balancing
time to first token
How to Approach This
  1. Start by clarifying functional and non-functional requirements with the interviewer.
  2. Estimate the scale: QPS, storage, bandwidth. This drives your design decisions.
  3. Draw a high-level architecture first, then deep dive into 1-2 critical components.
  4. Discuss trade-offs explicitly (e.g., consistency vs availability, SQL vs NoSQL).
  5. Address failure scenarios, monitoring, and how the system handles 10x traffic spikes.
Possible Follow-up Questions
  • How big is the KV cache for a 100k-token prompt on a large model, roughly?
  • How do you trade off cache affinity against load balance when one prefix is very hot?
  • Should cached prefixes ever be shared across organizations?
  • How do you bill cached versus uncached tokens fairly when hits depend on routing?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice System Design Problems
Sample Answer
Requirements
  • Automatically reuse KV for any prompt whose prefix (at least, say, 1,024 tokens) matches a recently seen one, within the same org.
  • Reduce TTFT and charge cached tokens at a discount.
  • No correctn...
High-Level Design
  • Tokenizer and prefix hasher at the router: split the prompt into blocks of 128 tokens and compute a rolling hash chain h_i = H(h_{i-1}, block_i, org_id, model_version).
  • *Cache-aware router...

Submit Your Answer
Markdown supported