AI System Design·Question 11 of 11Quick-fire

Design a semantic caching layer for an LLM API to cut cost. What are the failure modes?

Quick-fire answer from the Awesome Generative AI Guide (MIT)

Type it the way you would explain it to an interviewer. A few sentences is enough; you can't break anything.

Model answer: the part to lead with

Embed each incoming query, look up the nearest cached query, and if the similarity exceeds a tuned threshold return the stored answer instead of calling the model, otherwise call the model and store the new result. The main failure mode is a false hit: two queries look similar but need different answers (different dates, entities, or intent), so you serve a stale or wrong response, which is why you tune the threshold conservatively, scope caching to safe query classes, and consider a cheap verification step. You also handle invalidation (answers go stale when the underlying data changes) and personalization (a shared cache must not leak one user's answer to another). Instrument hit rate and false-hit rate so the cache is saving money without quietly degrading quality.

Full worked answer

Embed each incoming query, look up the nearest cached query, and if the similarity exceeds a tuned threshold return the stored answer instead of calling the model, otherwise call the model and store the new result. The main failure mode is a false hit: two queries look similar but need different answers (different dates, entities, or intent), so you serve a stale or wrong response, which is why you tune the threshold conservatively, scope caching to safe query classes, and consider a cheap verification step. You also handle invalidation (answers go stale when the underlying data changes) and personalization (a shared cache must not leak one user's answer to another). Instrument hit rate and false-hit rate so the cache is saving money without quietly degrading quality.

Learn more: Production topic

What a good answer covers

  • Embed each incoming query, look up the nearest cached query, and if the similarity exceeds a tuned…
  • The main failure mode is a false hit
  • You also handle invalidation (answers go stale when the underlying data changes) and personalization (a…
  • Instrument hit rate and false-hit rate so the cache is saving money without quietly degrading quality

Key terms: Learn more

Quick-fire answer from the Awesome Generative AI Guide (MIT) · answer text last updated 6 November 2026 · scoring and review schedule by LLM Prep