What is Redis and what makes it different from a traditional relational database?
Learn what Redis is, how the in-memory key-value store differs from a relational database, its data types, use cases and answers to common interview questions.
Expected Interview Answer
Redis is an open-source, in-memory key-value data store that keeps data in RAM for microsecond access, unlike a relational database that stores data on disk in normalized tables queried with SQL.
Where a relational database organizes data into rows and columns joined by keys and guarantees ACID transactions on durable disk storage, Redis holds structured values (strings, hashes, lists, sets, sorted sets) in memory and is accessed by direct key lookup. This makes Redis extremely fast but with a different durability and query model: no SQL joins, optional persistence, and a design centred on caching, real-time counters, queues, and ephemeral state rather than being the single source of truth.
- Microsecond read and write latency
- Rich data structures beyond simple strings
- Ideal as a cache in front of a slower database
- Built-in pub/sub, TTL expiry and atomic operations
- Horizontal scaling via clustering and replication
AI Mentor Explanation
A relational database is the official printed record book locked in the pavilion archive; accurate but slow to fetch. Redis is the scoreboard operator's mental tally and the LED display, updated instantly ball by ball so everyone sees the current run rate without waiting for the archive.
Step-by-Step Explanation
Step 1
Data lives in memory
Redis keeps its dataset in RAM, so reads and writes avoid disk seeks and complete in microseconds.
Step 2
Key-value access
You store and fetch values by a unique key rather than writing SQL queries against tables.
Step 3
Structured values
Values can be strings, hashes, lists, sets or sorted sets, each with specialised commands.
Step 4
Optional persistence
Redis can snapshot (RDB) or append-log (AOF) to disk so data survives restarts if you enable it.
Step 5
Use alongside a database
Typically Redis fronts a relational database as a cache or handles ephemeral real-time state.
What Interviewer Expects
- Clear grasp of in-memory versus disk-based storage
- Understanding of the key-value model and its trade-offs
- Awareness that Redis complements rather than replaces an RDBMS
- Knowledge of common use cases like caching and queues
- Mention of persistence options and durability trade-offs
Common Mistakes
- Claiming Redis is only a cache and cannot persist data
- Assuming Redis supports SQL joins and full relational queries
- Saying Redis loses all data on restart with no way to persist
- Treating Redis as a drop-in replacement for a primary database
Best Answer (HR Friendly)
“Redis is a very fast data store that keeps information in memory instead of on a hard drive, so it responds almost instantly. It is usually used alongside a traditional database to speed things up, for example by caching frequently needed data.”
Code Example
# Store and read a value by key
SET user:1:name "Ada"
GET user:1:name
# Set a value that expires after 60 seconds (cache TTL)
SET session:abc "token123" EX 60
# Atomically increment a counter
INCR page:viewsFollow-up Questions
- When would you choose Redis over a relational database, and when not?
- How does Redis persist data to disk?
- What happens to Redis data when the server restarts?
- How does Redis handle concurrency and atomic operations?
- What are the memory limits and eviction policies in Redis?
MCQ Practice
1. Where does Redis primarily store its data for fast access?
Redis is an in-memory store, keeping data in RAM to achieve microsecond latency.
2. Which statement best describes Redis compared with a relational database?
Redis is a key-value store offering strings, hashes, lists, sets and sorted sets rather than relational tables and joins.
3. How can Redis survive a restart without losing data?
Redis offers RDB point-in-time snapshots and AOF append-only logging so data can be recovered after a restart.
Flash Cards
What is Redis? — An open-source, in-memory key-value data store used for caching, real-time data and messaging.
Redis vs RDBMS storage? — Redis keeps data in RAM for speed; an RDBMS stores normalized tables on disk queried with SQL.
Is Redis only a cache? — No. It is commonly used as a cache but also supports persistence, queues, pub/sub and counters.
How does Redis persist data? — Via RDB snapshots or AOF (append-only file) logging to disk.
Continue Learning
Related Interview Questions
What are the core data types in Redis and when do you use each?
medium
How does Redis achieve its high performance as an in-memory store?
hard
What is a cache stampede (thundering herd) and how do you prevent it in Redis?
hard
What is the difference between write-through, write-behind, and cache-aside patterns?
medium