Key-value cache with per-entry TTL

0
Remix

Implement an in-memory key-value cache where every write gives a key, a value and a time-to-live. Once an entry's time is up it must behave as if it was never written. Support set, get and delete, and explain your choices as you go.

Follow-ups that come up:

  1. get is the hot path, so keep it cheap and move cleanup of expired entries elsewhere (a background sweeper or sidecar). How do you find expired entries without scanning everything?
  2. Add a capacity limit with least-recently-used eviction on top of the expiry.
  3. Make it safe for concurrent callers.
  4. Write and run tests, including ones that control the clock.
NetflixTechnical phone screenLast asked Oct 2026
No answer yet. Write the first one; the best answer gets endorsed.