Redis Interview Questions: Answer the Cache Trade-Off

Redis interview questions are cache-design questions. Learn a repeatable spoken answer for data structures, eviction, persistence and consistency, with worked examples.

By AI Interview AssistantPublished 9 min read

Most Redis interview questions are really cache-design questions: why Redis over Memcached, which data structure fits, what happens when the cache is full or stale, and how you keep it consistent with the database. Answer each one by naming the property you need, the cost you accept, and the failure mode you handle, then ground it in a concrete example. That structure turns a quiz into a design conversation, and it works for the same handful of redis interview questions every time.

Why interviewers ask Redis questions at all

The question behind the question is whether you can choose a cache and defend its cost. Nobody needs you to recite SET and GET. They want to hear whether you know what you are buying, what it costs, and what breaks at 3 a.m. when it does.

Five decision points cover most of what you will be asked:

  • Data structure: which one fits the access pattern, and at what complexity.
  • Eviction: what happens when memory fills, and what your application does about it.
  • Persistence: whether losing the data is acceptable.
  • Consistency: how the cache stays in step with the database, and how long it may lag.
  • Redis versus Memcached: which one your requirements actually call for.

A reliable way to open any answer: name the property you need, the cost you accept, then the failure you handle. "I need sub-10 ms reads on a product page, so I accept bounded staleness and handle the miss path." One sentence, and the rest of the answer has somewhere to go.

The data-structure question: pick, then justify

Naming the structure is half the answer. Say the operation and its cost in the same breath, and you have shown you would use it rather than describe it.

Worked example: a leaderboard for a large player base

Assume the game has 2 million players and each one has a score. The requirement is a top-100 board that refreshes constantly.

With a sorted set, each score update is one ZADD, and each read of the top 100 is one ZREVRANGE with the score range:

ZADD leaderboard 4210 player:8812
ZREVRANGE leaderboard 0 99 WITHSCORES

A sorted set is kept in order, so ZADD costs O(log N) for the insert and reposition. Each update therefore touches a number of comparisons that grows with the logarithm of the player count, not with the player count itself. ZREVRANGE for 100 entries costs O(log N + 100): the lookup plus the slice you actually return.

The alternative is storing scores in the database and sorting in the application on every read. That is O(N log N) per read over the whole player table, which is far too much work per page view. The sorted set moves the ordering cost to write time, where updates are spread out, and makes reads cheap. That is the trade: slightly more work per score change, dramatically less per leaderboard view.

Worked example: rate limiting one API key to 100 requests a minute

A counter per key, incremented on each request, with an expiry set on first use:

INCR ratelimit:key:9f2c
EXPIRE ratelimit:key:9f2c 60

INCR returns the new value, so the application rejects the request when the count exceeds 100. The EXPIRE is what makes the window roll over. Set it only when INCR returns 1, or refresh it every call depending on whether you want a fixed or sliding window; either way, the counter must expire. A plain counter with no expiry leaks a key per API key forever, and memory grows with your customer list rather than your traffic.

The common mistake is naming the structure and stopping there. "I'd use a sorted set" invites "why, and what does an update cost?" Saying "a sorted set, because ZADD is O(log N) and reads of the top 100 stay cheap" closes that follow-up before it opens.

Eviction: what happens when memory fills

Start with an estimate, and label every assumption. Assume 5 million cached user profiles, roughly 1 KB of value each:

5,000,000 profiles x 1 KB per value = 5,000,000 KB
5,000,000 KB / 1,024 = about 4,883 MB
4,883 MB / 1,024 = about 4.8 GB of values

So the values alone are about 5 GB. That is not your maxmemory setting. Redis adds per-key overhead for the key name, the object headers and the internal structures, so the real footprint is higher. State the assumption, show the arithmetic, then add headroom before you pick a number. An answer that says "about 5 GB, plus overhead, so I'd size above that and watch used_memory" is stronger than a confident figure with no working.

Then choose a policy and say what it does when memory is full:

  • allkeys-lru evicts the least recently used keys across the whole keyspace. It suits a pure cache, where any key can be rebuilt from the database.
  • noeviction refuses writes once memory is full and returns an error. It suits a case where Redis also holds data you cannot lose, because losing it silently is worse than a failed write.

The follow-up you should expect: what does your application do on a miss after eviction? The honest answer is that it reads through to the database, rebuilds the key, and that a burst of misses on the same key is the danger. A stampede guard, such as a short lock so only one request rebuilds a given key while the others wait or serve stale data, keeps a cold cache from becoming a database outage.

Persistence and the cache-versus-store decision

RDB snapshots write the dataset to disk at intervals. They are compact and fast to load, but a crash loses everything since the last snapshot. AOF logs each write, which narrows the window of loss at the cost of more disk writes and a slower recovery as the log is replayed. Say which risk you are buying down and what you pay for it.

The line worth saying out loud: if losing the data is acceptable, treat Redis as a cache; if it is not, you have chosen a database and must plan for durability. That single sentence settles most persistence questions, because it shows you know the difference between a cache and a store.

The mistake is calling Redis "just a cache" while storing session data in it with no persistence plan. Sessions that vanish on restart log every user out. The fix is to name the recovery behaviour: either persist, or accept re-login, or keep sessions elsewhere. Naming it is the answer.

Keeping the cache consistent with the database

For reads, use cache-aside: check the cache, and on a miss read the database, populate the key with a TTL, and return. For writes, update the database first, then delete the key rather than overwrite it. Deleting is safer with concurrent writers, because two updates racing to set the key can leave the older value in place, while a delete forces the next read to reload from the database.

A TTL is the safety net. Even if an invalidation is missed, a short TTL bounds how long stale data can live. The failure to narrate is a stale read after a failed delete: the write succeeded, the delete did not, and the old value sits there until the TTL expires. The fixes are a retry on the delete, or versioned keys so a new write lands under a new key name and the old one ages out. Either way, say the failure and the bound.

Redis vs Memcached: answer with criteria, not a verdict

CriterionRedisMemcached
Data structuresStrings, lists, sets, sorted sets, hashes, streamsStrings only
PersistenceRDB snapshots and AOFNone
ReplicationBuilt inNot built in
MultithreadingLargely single-threaded command executionMultithreaded
Operational complexityMore features and settings to runMinimal moving parts

For a simple string cache where you want minimal moving parts, Memcached is the honest answer. For a feature that needs sorted sets, streams or pub/sub, or that needs persistence, Redis wins, and you accept the cost of operating the extra features you now depend on. Answer with the criterion that decides it for your case, not a general verdict.

The one rule to carry into the room

Every Redis answer ends with the failure mode you handle and the cost you accepted. If you can say both, the follow-up becomes a conversation rather than a trap. Practise out loud with a timer: two minutes per answer, then one follow-up, and check whether you actually named the trade-off or only described the feature. For the wider design conversation, see how to narrate a distributed cache design, and pair this with backend interview trade-off answers so the habit carries across topics.

Frequently asked questions

Do I need to memorise Redis commands for the interview?

No. Learn the handful of operations that map to your chosen structures, such as ZADD and ZREVRANGE for a sorted set or INCR and EXPIRE for a counter, and know their complexity. Interviewers care that you can justify the choice and its cost, not that you can recall every command from memory.

What if I have never used Redis in production?

Say so plainly, then reason from a system you have built or a small project you can run locally. Describe the access pattern, the structure you would pick, the eviction policy and the failure you would handle. Honest reasoning about a cache you have not run beats a confident recital you cannot defend when asked a follow-up.

How do I answer a Redis question in a system design round rather than a quiz round?

Treat it as part of the design. State the read latency target, place the cache in the request path, choose the structure and eviction policy, and say how writes invalidate keys and what staleness you accept. Then name the failure mode, such as a stampede after eviction, and how you would guard against it.

Is it bad to say I would just use a managed Redis service?

Not at all, as long as you say what you are still responsible for. A managed service handles patching and failover, but you still choose the eviction policy, size memory from an estimate, set TTLs and handle misses. Naming those responsibilities shows you understand the trade-off rather than outsourcing the thinking.

Practising cache answers out loud? See how AI Interview assistant works.

A coffee shop counter with a small shelf of ready-made cups placed within easy reach of the barista

11 min read

Narrate a Distributed Cache System Design Interview

A 35-minute, narrated walkthrough for a distributed cache system design interview: scope the requirements, sketch the architecture, pick a strategy and defend the trade-offs.

  • Distributed cache system design interview
  • Design distributed cache
A night view from above of glowing city clusters connected by faint light lines across a continent

12 min read

CDNs System Design Interview: Edge Caching Reasoning

A practical way to handle CDNs in a system design interview: the problem they solve, what to cache, cache keys, TTLs, invalidation and the trade-offs to name out loud.

  • Cdns system design interview
  • Cdns interview explanation
A workstation with a monitor showing request and response arrows between two boxes, a keyboard and an API sketch

9 min read

Backend Development Interview Questions: Define, Then Trade Off

Backend development interview questions are trade-off questions in disguise. Learn a two-part answer shape, a worked idempotency answer and a 20-minute practice routine.

  • Backend development interview questions
  • Backend development interview answers