Caches - Redis vs Memcached vs DragonflyDB vs KeyDB#
The four most-asked in-memory stores. Redis dominates production today, but knowing why the alternatives exist sharpens the answer.
Side-by-side#
| Redis | Memcached | DragonflyDB | KeyDB | |
|---|---|---|---|---|
| Architecture | single-threaded event loop | multi-threaded | multi-threaded (modern) | multi-threaded fork of Redis |
| Data structures | rich (Strings, Lists, Sets, Hashes, ZSets, Streams, Bitmaps, HLL, Geo) | strings only | Redis-compatible + JSON | Redis-compatible |
| Throughput single node | 100k-1M ops/s | 1M+ ops/s (multi-core) | several million ops/s | high (parallelism on one box) |
| Persistence | RDB snapshot + AOF log | none | snapshot + AOF | snapshot + AOF |
| Replication | async leader-follower | client-side | async + multi-master option | async + active-active |
| Cluster | Redis Cluster (slots) | client-side hashing | drop-in | drop-in |
| Pub/Sub | yes (incl. Streams) | no | yes | yes |
| Lua scripting | yes | no | yes | yes |
| Eviction policies | many (LRU / LFU / TTL) | LRU only | many | many |
| Use case | almost everything | pure RAM cache, no features | high-throughput Redis replacement | multi-core Redis on one box |
When each wins#
- Redis - the safe default. Rich data structures (sorted sets for leaderboards, streams for queues, geo for proximity), Lua scripts for atomic ops, mature client libraries, Pub/Sub.
- Memcached - when you want pure single-data-structure caching, multi-core throughput on one box, and no features to misuse. Pure read-only cache farms still use it.
- Dragonfly - Redis API but multi-threaded on a single box. Lifts the single-CPU ceiling without sharding. Good when you can replace Redis with no API change.
- KeyDB - fork of Redis that adds multi-threading + active-active. Maintained by Snap; less momentum than Dragonfly.
Quick chooser#
flowchart TB
Q[Cache choice]
Q --> A{Rich data structures<br/>+ persistence?}
A -->|yes| B{Hit single-CPU<br/>throughput ceiling?}
B -->|no| RED[Redis]
B -->|yes| DRA[Dragonfly]
A -->|no| MEM[Memcached]
classDef p fill:#dbeafe,stroke:#1e40af,stroke-width:1px,color:#0f172a;
classDef s fill:#fef3c7,stroke:#92400e,stroke-width:1px,color:#0f172a;
class Q,A,B p;
class RED,MEM,DRA s;
What you'll get asked#
- "Why is Redis single-threaded?" → simplicity, atomicity per command, throughput ceiling per box → scale horizontally with Cluster.
- "When would you choose Memcached over Redis?" → pure cache, no persistence, multi-core single-box throughput, no rich types needed.
- "How does Redis Cluster differ from sentinel?" → Cluster shards data across nodes (16k slots); Sentinel is HA monitoring + failover for a single shard.
- "Use case for sorted sets?" → leaderboards, rate limiting (sliding-window), priority queues.
- "What's a hot key, and how do you mitigate?" → one key getting all traffic; replicate, pre-compute, or split into N sub-keys.
Real numbers#
| Scenario | Redis (single) | Memcached (single, 8 cores) | Dragonfly (single, 8 cores) |
|---|---|---|---|
GET ops / s |
100-200k | 1M+ | 2-4M+ |
| p99 latency | < 1 ms | < 1 ms | < 1 ms |
| Memory overhead | ~80 bytes / key | ~50 bytes / key | similar |
Glossary & fundamentals#
| Tag | Concept | Page |
|---|---|---|
HLD |
Caching strategies | caching-strategies |
HLD |
Consistent hashing (client-side sharding) | consistent-hashing |
HLD |
Distributed cache (cluster design) | distributed-cache |
HLD |
Replication leader/follower | replication-leader-follower |
FAQ#
Should I use Redis or Memcached?#
Use Redis for almost every modern workload. Pick Memcached only when you need raw single-key cache with multi-threaded throughput and no persistence, data structures, or pub-sub.
What is the difference between Redis and DragonflyDB?#
DragonflyDB is a multi-threaded drop-in replacement for Redis that scales vertically on a single node, often 5 to 25 times faster on multi-core machines. Single-threaded Redis is more battle-tested in clusters.
Is KeyDB still maintained?#
KeyDB development slowed after Snap acquired it, and most teams now look at DragonflyDB or Redis Cluster for multi-core scaling. Existing KeyDB deployments still work but new projects rarely pick it.
Can Redis replace a database?#
Not for primary storage of critical records. Redis can be a system of record for ephemeral state, leaderboards, sessions, and rate limiters, but durable transactional workloads belong in a real database.
How do I scale Redis beyond one node?#
Use Redis Cluster for horizontal sharding across many nodes, or a managed service like ElastiCache or Upstash. Plan keyspace and slot mapping carefully because cross-slot transactions are not supported.
Further reading#
- 📑 Docs - Redis - official documentation
- 📑 Docs - Memcached - wiki
- 📑 Docs - Dragonfly documentation
- 📄 Paper - Facebook - Scaling Memcache at Facebook (NSDI '13)
- ✍️ Blog - Netflix EVCache