Where does the data live?
- Traditional databases read from disk (SSD/HDD), so individual reads cost tens to hundreds of microseconds.
- Redis keeps the working dataset in RAM. RAM access is on the order of 100 nanoseconds — roughly a thousand times faster than disk.
Threading model: one main thread for command execution
Redis executes commands serially on a single main thread. This avoids locks, context switches, and synchronization overheads that arise with a multithreaded execution model.- If two clients modify the same key (for example,
product:42stock), Redis runs one command, then the next — no locks needed. - Small, deterministic commands complete quickly, so the single-threaded model achieves very high throughput.
- Since Redis 6, I/O threads can help with network read/write, but command execution still runs on the main thread.

How does one thread listen to thousands of clients?
Redis uses an event loop and I/O multiplexing so a single thread can efficiently manage many connections.- If 10,000 clients are connected but only 50 have data ready, Redis asks the OS which sockets are ready.
- On Linux, this leverages
epoll; the OS returns only sockets with data, Redis processes those, and then polls again. - This pattern (event loop + I/O multiplexing) avoids creating one thread per connection and minimizes context switching.

Redis achieves low latency by combining in-memory data with an event-driven loop. For network-heavy workloads, make sure client libraries and OS tuning (file descriptors, TCP buffers) are aligned with your connection count and throughput goals.
Data structures and protocol: predictable, compact, and fast
Redis stores and accesses data using structures designed for common access patterns:- Keys are stored in a hash table for ~O(1) lookups regardless of dataset size.
- Ordered collections (like sorted sets) use structures such as skip lists to maintain order without expensive re-sorts.
- Small values and objects are stored in compact encodings to reduce memory overhead and CPU cache misses.
- There is no SQL parsing or query planning stage — clients send simple commands using Redis’ RESP protocol, which is explicit about lengths and data layout.
product:42:
GET and product:42), with each bulk string preceded by its length. Because lengths are explicit, parsing is fast and deterministic.

Quick comparison: disk-based DB vs Redis (in-memory)
Trade-offs and pitfalls
The design choices that make Redis very fast also introduce trade-offs you must consider:- Memory: all working data must fit in RAM (or be sharded).
- Single-threaded execution: long-running commands block the main thread and delay other clients.
- Example:
KEYSon millions of keys walks the entire keyspace and will block Redis while it runs. - Prefer non-blocking alternatives like
SCAN, background processing, or running heavy commands on replicas.
- Example:

Summary
Redis is fast because:- Data lives in RAM (eliminating disk I/O latency).
- Command execution is single-threaded, avoiding lock contention.
- An event loop and I/O multiplexing let one thread efficiently serve many connections.
- Data structures and the RESP protocol are optimized for predictable, low-latency access.
Links and references
- Redis — official site
- RESP protocol specification
- epoll(7) — Linux manual
- Avoiding KEYS on production — Redis documentation on SCAN