Why Redis is fast, and Redis versus Memcached
In-memory storage, a single-threaded event loop and rich data structures, plus how persistence and replication work.
On the roadmap:Beginner · step 7: Caching basics
Lesson 9 of 23 · 8 min read · quiz · exercise
Why it is fast
- Everything lives in memory. No disk seek on the read path.
- Simple, efficient data structures (hash tables, skip lists, compact encodings) with predictable costs.
- A single-threaded event loop for command execution: no locks between threads, no context switching, and each command runs atomically. I/O multiplexing lets one thread serve thousands of connections.
- A lean protocol and in-process memory management.
(Newer versions use extra threads for network I/O, but command execution stays ordered.)
Image: Mixabest · Public domain · Source · Wikimedia Commons: Dual-channel DDR memory use 6026
How the pieces fit
Figure SDA-CORE-09-1 · Redis: event loop, memory, persistence and replication · © forcsguy.com
More than a cache
Redis stores typed values:
| Type | Use |
|---|---|
| String | cached values, counters, flags |
| Hash | objects with fields (a user profile) |
| List | queues, recent items |
| Set | unique members, tags, set maths |
| Sorted set | leaderboards, priority queues, time-ordered data |
| Others | streams, bitmaps, HyperLogLog, geospatial |
Because operations run on the server, you can increment, push, pop or intersect without a read-modify-write race.
Figure SDA-CORE-09-2 · Redis data types and what they are for · © forcsguy.com
Durability options
Memory is volatile, so Redis offers:
- Snapshots (RDB): periodic point-in-time dumps. Compact, but recent writes can be lost.
- Append-only file (AOF): logs every write; replays on restart. Safer, bigger and a little slower.
- Or none at all when it is purely a cache.
Scaling and availability
- Replication: a primary copies to replicas (asynchronously), serving reads and enabling failover.
- Sentinel / managed failover promotes a replica when the primary dies.
- Cluster: splits keys across nodes by hash slot, for data larger than one machine.
Redis versus Memcached
| Redis | Memcached | |
|---|---|---|
| Data types | many | strings only |
| Persistence | optional | none |
| Replication | yes | not built in |
| Threading | one for commands | multi-threaded |
| Best for | cache plus data structures, queues, counters | a very simple, large, pure cache |
For most new projects Redis is the more flexible choice. Memcached remains fine for a straightforward cache that must use many CPU cores.
Pitfalls
- Memory is finite: set a maxmemory and an eviction policy (for example LRU).
- Avoid slow commands on huge collections.
- A very hot key still concentrates load on one node.
Related reading
- Redis DocumentationRedis · Redis Ltd.Documentation
- Redis BlogRedis engineers · Redis Ltd.Blogs
- Redis UniversityRedis · Redis Ltd.Courses
- RedisRedis · Redis Ltd.GitHub
Show 6 moreShow fewer
- Redis persistenceRedis · Redis Ltd.Documentation
- Memory Optimization in Redis at WattpadWattpad engineers · WattpadCase Studies
- Scale with Redis ClusterRedis · Redis Ltd.Documentation
- Scaling Job Queue with Redis at SlackSlack engineers · SlackCase Studies
- Moving persistent data out of Redis at GithubGithub engineers · GithubCase Studies
- PayPal Developer Community BlogPaypal engineers · PaypalBlogs
Check your understanding
Question 1 of 3
0 correct so far
Which is a main reason Redis is so fast?
Topics covered in this lesson
Try it: see a system in action
One tap in a real app already crosses a client, a server and a database. Watch it happen, then try scoping a brief a few different ways below.
The app
The same hand-picked list of deals, shown to everyone, refreshed every few minutes
What just happened
Tap the button to send a real request.
One tap in the app sends a real request. Watch where it actually goes.
Go further: the Builder
Once you know what to ask, the Builder is where you turn requirements into an architecture. Come back to this once you've met a few more concepts.
Try it yourself
You need (a) a cache of rendered pages, (b) a leaderboard of top players, (c) a rate limiter counter. State which Redis feature suits each.
Click what a strong design here would need:
More in Building blocks
© 2026 forcsguy.com. Original lesson text and diagrams. Books and sites linked above belong to their authors.