Redis interview questions and answers, from data types to Cluster

Redis interview questions test whether you can use an in-memory store without losing data or correctness: which data type fits a problem, how RDB and AOF persistence differ, what happens when memory runs out, and how caching patterns fail. Senior rounds move to replication, Sentinel versus Cluster, pub/sub versus streams, and why a Redis lock is weaker than it looks. Good answers name the command, its complexity and the failure mode in one breath.

By Published 10 min read

How Redis comes up in interviews

Redis is rarely the whole interview. It shows up as a follow-up in backend and system design rounds ("how would you cache this?", "how do you rate limit?"), as a dedicated section for platform and SRE roles that operate it, and as a design question on its own: build a leaderboard, a session store, a job queue or a rate limiter. Interviewers expect you to know the commands well enough to write them on a whiteboard and to know where Redis stops being the right tool.

If the company runs a managed service or Valkey, the fork maintained under the Linux Foundation, almost everything below carries over; check the provider's documentation for limits and supported commands.

Fundamentals: data types and the execution model

Basic Redis interview questions
QuestionWhat it testsWhat a strong answer shows
Why is Redis fast?ArchitectureData lives in memory, commands run one at a time on a main thread with no lock contention, and the event loop multiplexes many clients. Newer versions can use extra threads for network I/O, but command execution stays serial.
What does single-threaded execution mean for you as a user?Atomicity and latencyEach command is atomic. One slow command (KEYS on a large keyspace, a huge SMEMBERS, a long Lua script) blocks every other client for its duration.
Which data type would you use for a session, a leaderboard, a feed and unique visitors?Type selectionA hash for the session fields, a sorted set for the leaderboard, a list or stream for the feed, and a HyperLogLog for approximate unique counts in a few kilobytes.
Hash versus one string per field?Memory and accessA hash groups fields under one key, deletes and expires as a unit, and can use a compact encoding when small. Separate strings are simpler to shard and expire one by one; newer versions can also expire single hash fields (HEXPIRE).
How do sorted sets work, and what are their costs?ComplexityMembers ordered by score; adds and rank lookups are O(log N), and range reads add the number of returned items. Equal scores sort by member name.
How does key expiry work?TTL internalsKeys expire lazily when touched and through a periodic sampler that deletes expired keys in the background, so memory is not freed at the exact second.
KEYS or SCAN?Production safetyKEYS walks the entire keyspace in one blocking call. SCAN iterates with a cursor in small batches, may return a key twice, and is safe in production.
What do MULTI and EXEC guarantee?TransactionsQueued commands run in order with no other client's commands in between. There is no rollback: if one command fails at runtime, the others still apply.
What does WATCH add?Optimistic concurrencyIf a watched key changes before EXEC, the transaction is discarded and returns null, so the client re-reads and retries.
Why use a Lua script or a function?Server-side atomicityRead-then-write logic runs as one atomic unit without round trips, such as compare-and-delete for a lock. Keep scripts short, because they block the server too.
What are bitmaps and geospatial indexes good for?Specialized typesBitmaps for per-user daily flags in very little memory; GEO commands for nearby-point searches on a sorted set underneath.
Basic Redis interview questions. Scroll sideways on a small screen.
> ZADD board 3100 ana 2800 ben 3100 cy 1900 dee
(integer) 4
> ZRANGE board 0 2 REV WITHSCORES
1) "cy"
2) "3100"
3) "ana"
4) "3100"
5) "ben"
6) "2800"
> ZREVRANK board ben
(integer) 2
redis-cli on Redis 8.10. Ana and Cy tie on 3100, so the reverse range orders them by member name, highest first. Ben's rank is zero-based.

Persistence: RDB, AOF and durability

  • What is an RDB snapshot? A point-in-time binary dump written by a forked child process, using copy-on-write so the parent keeps serving. Compact and quick to load, but writes since the last snapshot are lost on a crash.
  • What is the AOF? An append-only log of write commands, replayed on restart. appendfsync controls durability: always (safest, slowest), everysec (the usual choice, up to about a second of loss) or no (the OS decides).
  • Why does the AOF need rewriting? It grows forever. A rewrite produces the shortest log that recreates the current data, in the background.
  • Can you use both? Yes, and many production setups do: AOF for durability, RDB files for backups and fast replica bootstrapping.
  • Why can saving cause a latency spike? fork() on a process with a large memory footprint takes time, and copy-on-write can sharply increase memory use during heavy writes. Leave headroom and watch fork time in INFO.
  • Is Redis a database or a cache? Either, but say which. As a primary store you need AOF, replicas, backups and a plan for memory limits. As a cache you can lose it and rebuild from the source of truth.

Memory limits and eviction policies

maxmemory-policy values and when to use them
PolicyWhat it evictsFits
noeviction (default)Nothing; writes that need memory return an errorRedis used as a store where losing data is worse than failing a write
allkeys-lruLeast recently used keys, from all keysA general cache
allkeys-lfuLeast frequently used keysA cache with a stable set of popular keys and one-off scans
volatile-lru / volatile-lfuOnly keys with a TTLMixed use: cached keys have TTLs, important keys do not
volatile-ttlKeys with the nearest expiryWhen TTL already expresses priority
allkeys-random / volatile-randomRandom keysUniform access patterns
maxmemory-policy values and when to use them. Scroll sideways on a small screen.

Two follow-ups appear often. First, LRU and LFU are approximations: Redis samples a few keys and evicts the best candidate among them, which is cheap and close enough. Second, a volatile policy with no TTL keys behaves like noeviction, so writes start failing when memory fills.

Caching patterns and where they break

  • Explain cache-aside. The application reads Redis, falls back to the database on a miss, then writes the value with a TTL. On updates, write the database and delete the cache key rather than writing the new value, which avoids racing writers leaving a stale value.
  • Write-through versus write-behind? Write-through updates the cache and the store together on each write. Write-behind acknowledges after the cache write and flushes later, which is fast but risks losing writes.
  • What is a cache stampede and how do you stop it? A hot key expires and hundreds of requests rebuild it at once. Use a short rebuild lock, serve the stale value while one worker refreshes, or refresh early with some randomness.
  • What is cache penetration? Requests for keys that exist nowhere skip the cache every time. Cache the empty result briefly or check a Bloom filter first.
  • Why add jitter to TTLs? Keys written together expire together and cause synchronized misses. Randomizing TTLs by a few percent spreads the load.
  • What are hot keys and big keys? A hot key overloads one shard; a big key (a hash with millions of fields) makes deletes, migrations and replication slow. Split them, and delete big keys with UNLINK, which frees memory in the background.
  • How would you build a rate limiter? INCR on a per-client, per-window key with an expiry for a fixed window, or a sorted set of timestamps for a sliding window. See the full design in rate limiter system design.
> INCR rl:ip:203.0.113.9:202612031405
(integer) 1
> EXPIRE rl:ip:203.0.113.9:202612031405 60 NX
(integer) 1
> TTL rl:ip:203.0.113.9:202612031405
(integer) 60
Fixed-window rate limiter for one minute, run on Redis 8.10. EXPIRE with NX (Redis 7.0 and later) sets the TTL only on the first hit of the window.

Pub/sub, streams and queues

Messaging questions
QuestionWhat it testsWhat a strong answer shows
Pub/sub or streams for order events?Delivery semanticsPub/sub is fire-and-forget: a disconnected subscriber misses messages and nothing is stored. Streams are an append-only log with IDs, retained until trimmed, so consumers can catch up.
How do consumer groups work?StreamsXREADGROUP hands each entry to one consumer in the group. Entries stay in the pending list until XACK, so a crashed worker's messages can be claimed by another (XAUTOCLAIM).
How do you bound a stream's size?RetentionXADD with MAXLEN or MINID, usually the approximate form with ~ for efficiency, or XTRIM on a schedule.
How do you build a reliable queue with lists?Classic patternBLMOVE from the queue into a per-worker processing list, remove it when done, and have a reaper return stale items. Streams now cover most of this natively.
When is Redis the wrong message broker?JudgmentWhen you need long retention, replay of large histories, many independent consumer groups at high volume or strong durability across failover. A log-based broker fits better.
Messaging questions. Scroll sideways on a small screen.
> XADD orders * order_id 1001 status paid
"1796305210672-0"
> XADD orders * order_id 1002 status paid
"1796305210676-0"
> XGROUP CREATE orders billing 0
OK
> XREADGROUP GROUP billing worker-1 COUNT 10 STREAMS orders >
(two entries returned)
> XACK orders billing 1796305210672-0
(integer) 1
> XPENDING orders billing
1) (integer) 1
A stream with one consumer group, run on Redis 8.10. Both entries are pending for worker-1 until acknowledged; after one XACK, one remains. Entry IDs are timestamps and will differ.

Replication, Sentinel and Cluster

  • How does replication work? Asynchronous: the primary streams its write commands to replicas. After a short disconnect a replica resumes from the replication backlog (partial resync); after a long one it needs a full resync from a fresh RDB.
  • Does WAIT make Redis strongly consistent? No. WAIT blocks until a number of replicas acknowledge the writes, which lowers the chance of loss, but a failover can still promote a replica that missed them.
  • What does Sentinel do? A set of Sentinel processes monitors one primary and its replicas, agrees by quorum that the primary is down, promotes a replica and tells clients the new address. It does not shard data.
  • What does Redis Cluster do? It splits the keyspace into 16,384 hash slots spread across several primaries, each with replicas, and handles failover itself. Clients follow MOVED and ASK redirects.
  • Why does MGET fail in Cluster mode? Multi-key commands, transactions and scripts need all keys in the same slot. Hash tags fix it: keys like {user:42}:cart and {user:42}:profile hash only the part in braces.
  • Sentinel or Cluster? Sentinel when the data fits one machine and you want high availability. Cluster when you need more memory or write throughput than one primary gives, and can live with the multi-key limits.

Distributed locks: the senior follow-up

Almost every senior Redis interview reaches locks. The basic recipe is correct and short; the caveats are what the interviewer is waiting for.

> SET lock:order:42 3f9c1a PX 30000 NX
OK
> SET lock:order:42 other PX 30000 NX
(nil)

> EVAL "if redis.call('GET', KEYS[1]) == ARGV[1] then return redis.call('DEL', KEYS[1]) else return 0 end" 1 lock:order:42 wrong-token
(integer) 0
> EVAL "if redis.call('GET', KEYS[1]) == ARGV[1] then return redis.call('DEL', KEYS[1]) else return 0 end" 1 lock:order:42 3f9c1a
(integer) 1
Run on Redis 8.10. SET with NX and PX takes the lock only if it is free; the release script deletes it only for the owner's random token, so a wrong token returns 0.
  • Why not DEL to release? If your lock expired and someone else took it, a plain DEL removes their lock. The token check prevents that.
  • What if the holder pauses longer than the TTL? A long GC pause or network stall lets the lock expire while the old holder still thinks it owns it. Two clients then act at once.
  • What does failover do to a lock? Replication is asynchronous, so a lock written to the primary may not reach the replica that gets promoted. The new primary has no lock.
  • What are fencing tokens? A number that increases with every lock grant, passed to the protected resource, which rejects writes carrying an older number. This is what makes a lease safe; Redis alone cannot enforce it.
  • What is Redlock, and is it safe? Taking the lock on a majority of independent Redis primaries. Its safety under clock jumps and pauses has been publicly debated; a balanced answer is that it is fine for efficiency (avoiding duplicate work) and not enough for correctness without fencing.

Operations scenarios

Things that go wrong with Redis in production
ScenarioLikely causeFirst step
Latency spikes every few minutes.fork() for RDB or AOF rewrite on a large instanceCheck INFO persistence and the latest fork time; move snapshots to a replica.
Writes fail with an OOM error.maxmemory reached under noevictionDecide if this is a cache; if so set an eviction policy and TTLs, otherwise add memory or shard.
One shard runs at 100% CPU while others idle.Hot keyFind it with redis-cli --hotkeys (needs an LFU policy) or client-side sampling; replicate reads or split the key.
SLOWLOG shows a command taking 800 ms.O(N) command on a big keyReplace HGETALL or SMEMBERS on huge keys with HSCAN or SSCAN, or restructure the data.
Memory used is far above the dataset size.Fragmentation or big buffersCheck mem_fragmentation_ratio and client output buffers; active defragmentation can help.
Things that go wrong with Redis in production. Scroll sideways on a small screen.

Fictional example

Answering "Our product page cache melts the database at midnight. Why?"
Interviewer
We cache product pages in Redis with a 24-hour TTL. Every night around midnight the database CPU hits 100% for a few minutes. What is happening?
Candidate
My guess is that the cache was warmed in one batch, so every key got the same TTL and they all expire at about the same moment. Each miss goes to the database, and popular products get rebuilt by many requests at once, which is a stampede on top of a mass expiry. I would add jitter, say 24 hours plus or minus an hour, so expiries spread out. For the hottest keys I would let one request rebuild under a short lock, using SET NX with a few seconds of TTL, while others get the stale value or wait briefly. If the data allows it, a background job can refresh popular keys before they expire. Then I would confirm with the hit rate from INFO stats and database query counts around midnight.

One-week Redis practice plan

  1. Day 1: typesRun a local server and model a session, a leaderboard, a feed and unique visitors. Note each command's complexity.
  2. Day 2: atomicityWrite the same counter with GET then SET, with INCR, with MULTI/EXEC plus WATCH and with a Lua script. Explain which ones race.
  3. Day 3: memorySet a small maxmemory, try each eviction policy under a load script, and watch evicted_keys in INFO.
  4. Day 4: persistenceEnable AOF with everysec, kill the server mid-write and restart. Compare with RDB-only.
  5. Day 5: messagingBuild a stream consumer group, crash a worker on purpose and reclaim its pending entries.
  6. Days 6 and 7: scaleStart a small cluster locally, try a multi-key command across slots, fix it with hash tags, then rehearse the lock caveats aloud.

Redis usually sits next to a relational database, so pair this page with PostgreSQL interview questions or MySQL interview questions. MongoDB interview questions covers the document-store choice, and the caching chapter of the system design guide goes deeper on invalidation and layers.

Many Redis answers fall apart on the caveat, not the command. Natively, an AI interview assistant for Mac and Windows, keeps a live transcript of a mock round on your computer, so you can reread whether you raised failover and fencing before the interviewer had to ask. While practicing, it can read a design prompt or a SLOWLOG output from a screenshot and suggest an approach, and with Pro or the free trial it can work from the résumé and job description you add. Notes and transcript stay available afterwards.

Questions people ask

What Redis questions are asked in interviews?

Expect data types and their complexity, why Redis is fast, RDB versus AOF persistence, eviction policies, cache-aside and stampedes, pub/sub versus streams, replication, Sentinel versus Cluster and how to build a lock safely.

What is the difference between RDB and AOF in Redis?

RDB writes periodic point-in-time snapshots, compact and fast to load but losing writes since the last one. AOF logs every write command and replays it on restart; with fsync every second you lose at most about a second of writes.

What is the difference between Redis Sentinel and Redis Cluster?

Sentinel monitors one primary and its replicas and performs failover, but does not shard. Cluster splits keys across 16,384 hash slots on several primaries and handles failover itself, at the cost of restrictions on multi-key commands.

Is a Redis distributed lock safe?

SET with NX and an expiry plus a token-checked release is fine for avoiding duplicate work. It is not safe for correctness on its own, because a pause past the TTL or an asynchronous failover can let two clients hold it; add fencing tokens at the resource.

Where to go next

Practice with the same assistant you would use on a call: it listens, transcribes and suggests answers from your own resume and the job description.

Facts on this page were last checked on . Product details come from the Natively app itself; if something here is out of date, tell us at hello@heynatively.com.

Keep reading

Put it on your own machine.

A live-conversation assistant that runs locally. Your conversations stay on your machine.

macOS 12+ · Windows 10/11

© 2026 Natively AI Private Limited

Source-available under the Natively Personal Use Source License v1.0 · IP geolocation by DB-IP