Redis

Caching Patterns Interview Questions

Caching Patterns interview questions for Redis — fundamentals through advanced scenarios.

  • 20Questions with answers
  • 3Difficulty levels

Questions (20)

Browse beginner, intermediate, and advanced questions with answers — hide them when you want to self-test.

Question 1
Interview Beginner
Question

How does cache-aside work in Redis, and what is the usual failure mode?

Answer:

Cache-aside means the app reads Redis first, then the database on a miss, then SET with a TTL. The database remains source of truth. The failure mode is stampede when the hot key expires and every instance refills at once.

Question 2
Interview Beginner
Question

When would you choose write-through over cache-aside?

Answer:

Write-through updates Redis in the same request as the database write so the next read never sees a hole. Latency of the write path rises by a round trip. You still need TTL or eviction because cache and DB can diverge after partial failures.

Question 3
Interview Beginner
Question

What is write-behind caching, and what can you lose?

Answer:

Write-behind acknowledges the client after Redis, then flushes to the database asynchronously. Throughput looks great until Redis dies with unflushed writes. Treat it as a buffer with a documented loss window, not as durable storage.

Question 4
Interview Beginner
Question

What is a cache stampede and how do you notice it?

Answer:

A cache stampede is many clients missing the same hot key and slamming the database together. Locks with SET NX EX, probabilistic early expire, and TTL jitter are the usual defenses. Ignoring it shows up as periodic database CPU cliffs aligned with TTLs.

Question 5
Interview Beginner
Question

Why cache a negative lookup (not found) in Redis?

Answer:

Negative caching stores a short-lived sentinel for not-found so a missing row is not queried thousands of times. TTL must be short or a newly created row stays invisible. Empty HASH versus a dedicated miss marker should be a team convention.

Question 6
Interview Beginner
Question

What problem does TTL jitter solve on hot keys?

Answer:

TTL jitter spreads expiry by adding a random delta so sibling keys do not evaporate on the same second. Without jitter, a deploy that SET the same TTL on a million keys creates an eviction storm. Keep the jitter small relative to the mean TTL.

Question 7
Interview Beginner
Question

How do LRU eviction policies differ from noeviction on a cache?

Answer:

LRU eviction via allkeys-lru or volatile-lru drops least-recently-used keys when maxmemory is hit. volatile-* only touches keys that already have a TTL. Picking noeviction on a cache is how SET starts returning OOM errors in production.

Question 8
Interview Intermediate
Question

How does probabilistic early expiration reduce stampedes?

Answer:

Probabilistic early expiration refreshes a key before TTL hits zero, with probability rising as remaining life shrinks. One client recomputes while others still serve the old value. It beats a hard lock when the fill is expensive but not catastrophic to duplicate.

Question 9
Interview Intermediate
Question

How do you single-flight a cache fill with Redis?

Answer:

A single-flight lock uses SET NX EX on a lock key so only one client recomputes the cache fill. Others sleep and retry GET. If the lock holder dies, EX is what unblocks the herd; a lock without TTL is a permanent outage.

Question 10
Interview Intermediate
Question

What does CLIENT TRACKING change about local caches?

Answer:

CLIENT TRACKING enables client-side caching: the server invalidates a client local copy when watched keys change. BCAST and OPTIN change which keys are watched. Without TRACKING, a local Caffeine layer silently serves stale data after another pod writes.

Question 11
Interview Intermediate
Question

When must you use volatile-* eviction instead of allkeys-lru?

Answer:

volatile-ttl evicts keys closest to expiry among those that already have a timeout; allkeys-lfu and allkeys-lru can drop keys you meant to keep forever. Caches that mix durable config keys with cached rows need volatile-* so config is never evicted. Mixing policies in one instance is how sessions disappear.

Question 12
Interview Intermediate
Question

How do you bust a generation of cache keys without SCAN or FLUSHDB?

Answer:

Versioned key prefixes such as v3:user:42 let you invalidate a generation without SCAN. Bump the version in config and old keys expire via TTL or eviction. FLUSHDB as a cache-bust is a red flag on a shared Redis.

Question 13
Interview Intermediate
Question

When does LFU beat LRU for a Redis cache?

Answer:

LFU via allkeys-lfu tracks frequency so a once-hot key that went idle is dropped before a steadily popular one. LRU would keep the recently scanned one-hit wonder. lfu-log-factor and lfu-decay-time are the knobs when the counter saturates.

Question 14
Interview Intermediate
Question

Why is maxmemory-policy a cache-versus-store decision?

Answer:

maxmemory-policy noeviction is correct for Redis as a store: SET must fail rather than drop data. Caches want allkeys-lru or allkeys-lfu. Interviewers listen for that cache-versus-store split, not a memorized default.

Question 15
Interview Advanced
Question

How do you stop a stampede when a single NX lock becomes the hotspot?

Answer:

Stampede at millions of QPS needs jittered TTL, request coalescing, and sometimes a stale-while-revalidate read of a still-present key. One NX lock becomes the new hotspot. Serve slightly stale from Redis while a background worker refreshes.

Question 16
Interview Advanced
Question

What fails in write-behind when Redis restarts before the flusher runs?

Answer:

Durability of write-behind dies if AOF or RDB does not capture the buffer before a crash, and the async flusher has not reached the database. You then repair from logs or accept loss. Do not put payments on write-behind Redis.

Question 17
Interview Advanced
Question

What extra invalidation does a two-level cache (process memory plus Redis) need?

Answer:

Two-level caches require CLIENT TRACKING or very short local TTLs. Otherwise pod A serves a price that pod B already updated. Local caches without invalidation are the usual consistency bug in interviews.

Question 18
Interview Advanced
Question

Where does RedisBloom fit in a cache-aside miss path?

Answer:

RedisBloom BF.EXISTS before a database lookup cuts the negative-cache stampede for "does this email exist" at the cost of false positives. False positives mean an extra DB hit, not a wrong yes in billing. Size the filter with expected cardinality.

Question 19
Interview Advanced
Question

How is refresh-ahead different from letting every web thread refill?

Answer:

Refresh-ahead uses a worker that watches TTLs or a STREAM of invalidations and rewrites keys before they die. It is safer than every web thread racing to fill. The worker must be sharded or it becomes the stampede.

Question 20
Interview Advanced
Question

Should cache-aside fills use WATCH and MULTI?

Answer:

Cache-aside races are usually accepted: two SET of the same value are fine. WATCH plus MULTI is for compare-and-set on a value you cannot clobber, not for ordinary cache fills. Overusing Redis transactions here is a smell.

Practice with AI mock interviews

Run Redis mock interviews with AI follow-ups, instant feedback, and analytics on AiLx.

Free to start · No credit card required