Try
↑ ↓ move↵ openesc close

Interview prep / Caching

Senior · Caching · System design interview question

A batch job scans a large table once, and your cache hit rate collapses for everyone else. Why, and what eviction designs resist it?

Sketch your own answer first, then compare it with the one below.

A strong answer

A scan touches many keys once each. With plain LRU, every one of those keys is inserted as most recently used, so together they push out the genuinely hot keys. When the scan finishes the cache is full of keys that will not be requested again.

The core fix is to stop a single access from earning a long stay.

  • Segmented designs such as SLRU put new keys in a probationary segment and promote only on a second hit.
  • LRU-K bases eviction on the time of the K-th most recent access, so a key touched once looks old.
  • ARC balances recency against frequency adaptively, and keeps ghost entries of recently evicted keys to learn which side needs more room.
  • Admission policies such as TinyLFU admit a new key only if its estimated frequency beats the key it would replace. One-off scan keys lose.

On the operations side, run the scan against a replica, bypass the cache for known scans, or give the batch job its own small cache.

Sources

Learn it by running it

The caching and eviction lesson explains the mechanism behind this question, and its lab lets you change the parameters and watch the effect.

Your progress is saved in this browser. Sign in to keep it on every device. Privacy · Terms