Use Cases Interview Questions
Use Cases 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.
How would you store sessions in Redis, and what product choice is persistence here?
Session store: a STRING or HASH per session id with EXPIRE matching the cookie. HASH lets you HSET lastSeen without rewriting the blob. Losing Redis here logs everyone out, so persistence and replicas are product decisions, not just ops.
How do you implement a basic rate limit with Redis?
Rate limiting: INCR of a window key plus EXPIRE on the first increment is the basic limiter. Sliding windows use ZSET with timestamps as scores and ZREMRANGEBYSCORE. Fixed windows are simpler and burst at boundaries.
How do you model a leaderboard, and why not rebuild it on every read?
Leaderboards: ZSET score is the rank metric; ZREVRANGE gives top-N. Ties need a second score or lexicographic member. Do not rebuild the ZSET from SQL on every read; increment with ZINCRBY.
How does a safe Redis lock get released without deleting someone else lock?
Distributed lock: SET lock:order NX EX seconds is the basic lock. Release with a Lua compare-and-DEL of the token. Locks without a token DEL are unsafe; any client could drop someone else lock.
Why is LIST a weak job queue compared with STREAM?
Job queue: LIST LPUSH/BRPOP is a simple queue; crashed workers lose the popped job. STREAM plus XREADGROUP and XACK retries pending entries after XAUTOCLAIM. That is why STREAM replaced LIST for serious queues.
When is Redis GEO enough, and when is it not?
GEO: GEOADD plus GEORADIUS or GEOSEARCH for drivers near here. Radius queries on huge sets still scan a geohash range. For nationwide search you shard by region keys, not one global ZSET.
When would you count unique visitors with HyperLogLog versus a SET?
Unique visitors: HyperLogLog PFADD per day; exact uniques if the set fits in a SET. Billing uses SET or a database. HyperLogLog is for dashboards.
How do idempotency keys in Redis stop double charges?
Idempotency keys: SET idem:orderId NX EX 86400 around a payment. NX failure means already processed. Combine with the business record; Redis expiry must outlive retries.
Where should feature flags live so allkeys-lru cannot evict them?
Feature flags and config: a HASH of flags with Pub/Sub invalidation. allkeys-lru must not evict this key—use a separate instance or volatile-* only on cache keys. Mixing flag store and cache eviction is an outage.
How do you deduplicate events, and when is Bloom the wrong structure?
Dedup of events: SET with NX or Bloom BF.ADD for did we see this event id. Bloom false positives drop events; that may be wrong. For exactly-once, NX on a SET or STRING plus persistence.
How do you implement a sliding session TTL without stamping Redis on every click?
Sliding session: GET plus EXPIRE refresh, or HASH plus EXPIRE. Sliding TTL on every request can stampede Redis; refresh only when remaining TTL is below a threshold.
How would you model online presence without trusting Pub/Sub as the roster?
Multi-player presence: Pub/Sub for ticks, SET or ZSET of online user ids with a short TTL refreshed by heartbeat. Expired members leave. Do not trust Pub/Sub as the roster; the SET is the roster.
How do you schedule delayed jobs with ZSET without two workers grabbing one job?
Fair job scheduling: ZSET score equals run-at timestamp, workers ZRANGEBYSCORE plus ZREM in Lua. Without Lua, two workers grab the same job. This is a classic EVALSHA use case.
What goes wrong when you cache full HTML pages as huge STRING values?
Cache of rendered pages: STRING with TTL jitter, cache-aside from origin. Negative cache 404s briefly. Huge HTML values become big keys; compress or fragment.
Why is Redlock not a complete correctness story for distributed locks?
Redlock caveats: pause-the-process, clock drift, and majority failure modes mean Redlock is not a silver bullet for correctness. For a mutex around a side effect, a single Redis with fencing tokens or an external consensus store may be clearer. Know Kleppmann critique in interviews.
What still fails if a lock holder pauses past EX and then writes?
Distributed lock fencing: the lock token is not enough if the holder pauses past EX and another holder starts; the slow holder then writes anyway. A monotonically increasing fencing token checked by the storage layer is the real fix. Redis lock EX only bounds the critical section if the work is short.
How do you rate-limit on Cluster without a hot {global} counter?
Rate limit across Cluster: the counter key must not hot-slot a single {global} tag. Shard by user id. A single global INCR is a Cluster bottleneck.
How would you store per-user inboxes without creating unbounded STREAM keys?
Inbox and notifications: STREAM per user with MAXLEN approximate, or a LIST of recent ids. STREAM consumer groups if multiple notification workers. Per-user keys need hash tags only when multi-key ops apply.
Where does Redis GEO stop and a search engine start?
Geo plus search: Redis GEO does not replace Elasticsearch. Use GEO to shortlist ids then hydrate. Interviewers want that boundary.
When should you refuse to put a problem in Redis?
When not to use Redis: large relational queries, unbounded datasets that do not fit RAM, and strong multi-key transactions across entities. Redis is memory-first. For those, use a disk database and cache-aside.
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