Why Redis Is Fast: In‑Memory Storage, Specialized Data Structures, Single‑Threaded Model, and I/O Multiplexing
Redis achieves high performance by storing all data in memory, using compact data structures such as SDS, ziplist and skiplist, running a single‑threaded event loop with lock‑free execution, and employing efficient I/O multiplexing and incremental rehash techniques to minimize latency and maximize throughput.
Why Redis Is Fast
Redis achieves high performance because it is an in‑memory database, uses specialized data structures, runs a single‑threaded event loop with I/O multiplexing, and employs efficient memory‑management techniques such as SDS, ziplist, and incremental rehash.
Memory‑Based Storage
All data resides in RAM, eliminating disk latency.
Data Structures
Redis implements several compact structures:
Simple Dynamic Strings (SDS) replace C strings, storing length, free space, and buffer. Example definition: struct sdshdr { long len; long free; char buf[]; };
Linked lists for list when elements are many or large.
Hash tables (dict) for key‑space and expiration mapping, using chained hashing and incremental rehash.
Skip lists for ordered sets, providing O(log n) search.
Integer sets (intset) for small integer collections, with automatic upgrade of encoding. Definition: typedef struct intset { int32 encoding; int32 length; int contents; };
Ziplist for compact storage of short strings or integers in lists and hashes, with fields zlbytes , zltail , zllen , entry , and zlend .
Single‑Threaded Execution
The core network I/O and command processing run in a single thread, avoiding lock contention and simplifying concurrency.
I/O Multiplexing
Redis uses the operating‑system’s multiplexing primitives (epoll, kqueue, etc.) so one thread can monitor thousands of sockets simultaneously.
Performance Bottlenecks and Mitigations
Long‑running commands, big keys, massive expirations, eviction policies, and synchronous AOF flushing can block the thread. Redis 4.0 introduced lazy‑free for big‑key deletion, and Redis 6.0 added optional multi‑threaded I/O for client reads/writes while keeping command execution single‑threaded.
Summary
By combining an in‑memory model, carefully chosen data structures, a lock‑free single‑threaded design, and efficient I/O multiplexing, Redis delivers sub‑millisecond latency and high throughput.
IT Architects Alliance
Discussion and exchange on system, internet, large‑scale distributed, high‑availability, and high‑performance architectures, as well as big data, machine learning, AI, and architecture adjustments with internet technologies. Includes real‑world large‑scale architecture case studies. Open to architects who have ideas and enjoy sharing.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.