What is the difference between Redis and Memcached?
Compare Redis and Memcached: data structures, persistence, threading, and throughput, so you can choose the right in-memory cache for your use case.
Expected Interview Answer
Both are in-memory key-value stores used for caching, but Redis is a richer data-structure server with persistence, replication, and built-in features, while Memcached is a leaner, multi-threaded cache focused purely on fast string/object caching.
Memcached stores simple string values and shines at high-throughput, multi-core caching of small, uniform objects with a very simple protocol. Redis adds native data types (lists, sets, sorted sets, hashes, streams), optional persistence (AOF/RDB), replication and clustering, pub/sub, transactions, Lua scripting, and TTL semantics, making it a general-purpose data platform. Memcached is multi-threaded and can edge out Redis on raw simple-GET throughput per node, whereas Redis is largely single-threaded per instance but far more capable.
- Redis offers rich data structures beyond plain strings
- Redis supports persistence, replication, and clustering
- Redis adds pub/sub, transactions, and Lua scripting
- Memcached is multi-threaded for simple high-throughput caching
- Memcached has a simpler model and lower memory overhead per key
AI Mentor Explanation
Memcached is like a scoreboard that only shows the running total: fast, simple, and it forgets everything at close of play. Redis is the full match-analytics system that also keeps ball-by-ball data, partnerships, and saved records to disk. If all you need is the score, the scoreboard is quicker; if you need deep stats and history, you want the analytics system.
Step-by-Step Explanation
Step 1
Start with the shared purpose
Note both are in-memory key-value caches that speed up reads by avoiding slower databases.
Step 2
Compare data models
Memcached stores plain strings; Redis offers lists, sets, sorted sets, hashes, and streams.
Step 3
Compare persistence
Memcached is purely volatile; Redis can persist to disk via AOF and RDB and replicate.
Step 4
Compare threading and throughput
Memcached is multi-threaded; Redis is largely single-threaded per instance but far more feature-rich.
Step 5
Pick per use case
Choose Memcached for simple high-volume string caching, Redis when you need structures, persistence, or pub/sub.
What Interviewer Expects
- Both are in-memory key-value stores
- Redis has rich data structures, Memcached stores strings
- Redis supports persistence and replication, Memcached does not
- Memcached is multi-threaded; Redis is largely single-threaded
- A use-case-driven recommendation for choosing between them
Common Mistakes
- Claiming Memcached supports lists, sets, or persistence
- Saying Redis cannot scale or is always slower
- Ignoring Memcached's multi-threaded throughput advantage
- Treating them as identical caches with no trade-offs
- Forgetting Redis extras like pub/sub, Lua, and transactions
Best Answer (HR Friendly)
“Both Redis and Memcached keep data in memory to make apps faster, but Memcached is a simple, lightweight cache for plain values, while Redis does much more, offering different data types, saving data to disk, and features like messaging. You pick Memcached for pure simple caching and Redis when you need more capability.”
Code Example
# Memcached: strings only
set user:1 0 3600 4
Adam
get user:1
# Redis: strings AND structured types
SET user:1 "Adam" EX 3600
HSET user:1:profile name Adam age 30 # hash
ZADD leaderboard 1500 user:1 # sorted set
LPUSH jobs "job-42" # list / queue
PUBLISH events "user-signed-up" # pub/subFollow-up Questions
- When would you still choose Memcached over Redis today?
- How does Redis persistence (AOF vs RDB) work?
- Why is Redis mostly single-threaded, and how does it scale?
- Which Redis data structure would you use for a leaderboard?
- How do eviction policies differ between Redis and Memcached?
MCQ Practice
1. Which capability does Redis have that Memcached lacks?
Redis adds data structures (lists, sets, hashes, sorted sets) and optional disk persistence, which Memcached does not provide.
2. Which statement about threading is correct?
Memcached is multi-threaded and can exploit multiple cores; a Redis instance is largely single-threaded for command execution.
3. For a simple high-throughput cache of small string objects, which is the leaner choice?
Memcached's simpler model and multi-threading make it a lean fit for plain, high-volume string caching.
Flash Cards
Core difference in data model? — Memcached stores strings only; Redis supports lists, sets, sorted sets, hashes, and streams.
Persistence? — Redis can persist to disk (AOF/RDB) and replicate; Memcached is purely volatile.
Threading? — Memcached is multi-threaded; a Redis instance is largely single-threaded per command execution.
When to pick Memcached? — For simple, high-throughput caching of small, uniform string objects with minimal overhead.
Continue Learning
Related Interview Questions
What are the trade-offs of using Redis for session storage?
medium
What is Redis and what makes it different from a traditional relational database?
easy
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