Redis Interview Questions
Q: What is Redis and what is it used for?
Redis is an in-memory data structure store used as a cache, message broker, session store, rate limiter, and real-time leaderboard. All data is in RAM, making it extremely fast (sub-millisecond reads/writes). It supports optional persistence (RDB snapshots, AOF log) for durability.
Q: What are the main data types in Redis?
String — text, numbers, binary data (max 512MB)
List — ordered linked list, queue/stack operations
Set — unordered unique elements, set operations (union, intersection, diff)
Sorted Set (ZSet) — unique elements with a score, sorted by score — leaderboards, time-based data
Hash — field:value pairs, like a flat object
Stream — append-only log, like Kafka — event sourcing
Q: How does Redis persistence work?
RDB (Redis Database) — periodic snapshots of the dataset to disk. Fast to load on restart, but data written since last snapshot is lost on crash. AOF (Append Only File) — logs every write command. Can be configured to fsync always/every second/never. AOF provides much better durability but larger files. Both can be used together.
Q: What is the difference between KEYS and SCAN?
KEYS pattern blocks the server until it scans the entire keyspace — never use in production. SCAN uses cursor-based iteration, returning a small batch of keys per call without blocking. Iterate until cursor returns 0.
Q: How do you handle cache invalidation?
Three strategies: (1) TTL — set expiry and let cache expire naturally (eventual consistency). (2) Active invalidation — delete/update cache key when the underlying data changes. (3) Event-driven — publish a cache invalidation event and all consumers clear their local caches. Cache invalidation is notoriously hard — one of the "two hard problems" in CS.
Q: Is Redis single-threaded?
The command processing engine is single-threaded (one command at a time), which makes all operations atomic without locking. Since Redis 6.0, I/O threads handle reading/writing network data in parallel, improving throughput. Background threads handle persistence (RDB, AOF rewrite) and lazy freeing.
Keep your own version of these notes — editable, searchable, and organised by your stack.
Start free