Redis vs Memcached: Architecture Compared
On this page
Redis vs Memcached: the differences at a glance
Redis and Memcached are both in-memory key-value stores, both answer in well under a millisecond, and both are standard behind web apps. They come from different design philosophies, and the differences decide which one fits.
| Memcached | Redis | |
|---|---|---|
| Values | Strings and blobs | Strings, hashes, lists, sets, sorted sets, streams and more |
| Threads | Multi-threaded | Commands run on one main thread |
| Persistence | None | Snapshots and an append-only log (optional) |
| Replication and failover | None built in | Replicas, Sentinel, Cluster |
| Scaling out | Client hashes keys across servers | Redis Cluster shards by hash slot |
| Eviction | LRU per memory class | Configurable: LRU, LFU, TTL-based and more |
Memcached: a deliberately simple cache
Memcached does one thing: store blobs by key, with expiry, and evict the least recently used when memory fills. Its threads serve requests across all CPU cores. There's no persistence and no replication. Servers don't know about each other; the client library hashes each key to pick a server. If a server dies, its keys are simply gone and get reloaded from the database.
That simplicity is the point. For a pure cache of rendered fragments or serialized objects, there's very little to configure or go wrong. Facebook's "Scaling Memcache at Facebook" paper (2013) describes running it at enormous scale in front of MySQL.
Redis: data structures on the server
Redis runs commands one at a time on a single thread, so each command is atomic without locks. Its real strength is the data types (the Redis in Depth course covers each in depth):
- Hash: a session or object whose fields update independently.
- Sorted set: a leaderboard or a time-ordered feed, kept sorted as scores change.
- List or stream: a queue; streams add consumer groups and acknowledgments.
- Counters with expiry: rate limits.
Because the server understands the structure, operations like "add 5 points and give me the new rank" happen in one fast call instead of fetching a blob, changing it and writing it back. Add optional persistence, replication with automatic failover, and Cluster for sharding, and Redis often serves as cache, session store, rate limiter and lightweight queue at once.
Three settings decide how it behaves under pressure:
- Memory limit and policy. Self-hosted Redis defaults to no memory limit and the
noevictionpolicy: when memory runs out, writes fail with errors instead of evicting old keys. For a cache, setmaxmemoryand a policy such asallkeys-lru(Day 34). Managed services often change these defaults, so check yours. - Persistence. Snapshots lose everything since the last one. The append-only log with
fsyncevery second can lose up to about a second of writes. Fine for a cache, not for the only copy of an order. - Cluster key rules. In Redis Cluster, a command or transaction that touches several keys only works if they live in the same hash slot. Group related keys with a hash tag, such as
{user:42}:cartand{user:42}:profile.
Single-threaded Redis vs multi-threaded Memcached
Memcached's threads use all cores on one server. Redis's single command thread means one server's throughput is bounded by one core for command execution, though that's often hundreds of thousands of simple operations per second, and I/O threads help with network work. Redis scales by adding nodes rather than cores. The single thread also means one slow command (like KEYS * or a huge HGETALL) blocks everyone.
Worked example: when to choose Redis or Memcached
- Rendered HTML fragments for a content site: opaque blobs, losing them is harmless, huge read volume. Memcached fits, and so does Redis used plainly. If you already run Redis, using it avoids running a second system.
- A live game leaderboard plus shared sessions: needs sorted sets, atomic score updates and sessions that survive a cache restart. Redis, clearly.
In practice many teams standardize on Redis (or Valkey, the fork created after Redis changed its license in 2024) because one system covers more needs. Memcached remains a good choice for very large, simple caching tiers.
Check yourself
Redis. Its sorted sets keep members ordered by score on the server, so ZINCRBY updates a score, ZREVRANGE returns the top 10 and ZREVRANK returns any player's rank, all in logarithmic time. Memcached only stores opaque values, so you'd have to sort in the application.
The default policy is noeviction, so a full Redis rejects writes. Set maxmemory and an eviction policy such as allkeys-lru for cache use.
Redis executes commands one at a time on a single thread. A long-running command, such as KEYS *, a huge LRANGE or a slow Lua script, blocks every other client's commands until it finishes, so one bad request raises latency for the whole application.
When you need a pure, simple cache of opaque values with very high multi-threaded throughput and no persistence, data structures or replication. Memcached's simplicity is its strength, but most teams pick Redis for its richer features.
With noeviction, a full Redis rejects writes instead of making room, so the cache starts failing at peak traffic. A policy like allkeys-lfu evicts the least useful keys automatically, which is what a cache should do.