Collapse Duplicate Concurrent Cache Misses With Single-Flight

Last updated: November 29, 2026

Quick Overview

When many requests miss the cache for the same key at once, ensure only one of them loads from the backend while the rest wait and share the result, including errors.

Google
Software Engineering Fundamentals
Software Engineer
Google
November 29, 2026
Software Engineer
Onsite
Software Engineering Fundamentals
Medium

0

0

0 solved


When many requests miss the cache for the same key at once, ensure only one of them loads from the backend while the rest wait and share the result, including errors.

Cache stampedes on hot keys are a recurring cause of backend overload in large services like YouTube or Search frontends. Interviewers check that you can build request coalescing correctly: one leader per key, waiter wakeup, error propagation, and cleanup.

What the Interviewer Expects
  • Ensures exactly one in-flight load per key
  • Waiters block without holding the global lock
  • Propagates the leader's exception to waiters
  • Removes the entry so later calls reload
  • Explains how this combines with a TTL cache
Key Topics to Cover
request coalescing
cache stampede
thread synchronization
error propagation
How to Approach This
  1. Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
  2. Choose data structures based on access patterns, not familiarity.
  3. Prefer immutable data and message passing over shared mutable state for concurrency.
  4. Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
  • How would you add a timeout for waiters?
  • How would you do this across many servers?
  • What about serving stale data while refreshing?
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
  • do(key, fn) returns fn's result. Concurrent callers with the same key share one execution.
  • If fn raises, every waiter for that flight sees the same exception.
  • Calls after the flight finishes s...
High-Level Design

A dict from key to an in-flight call object holding an Event, a value, and an error, protected by a short-held lock. The first caller becomes the leader and runs fn outside the lock; others wait on th...


Submit Your Answer
Markdown supported