Redis achieves sub-millisecond latencies by storing all data in memory and using an asynchronous single-threaded event loop.
1. Single-Threaded Event Loop (I/O Multiplexing)
Uses Linux epoll system calls to process thousands of client socket requests sequentially on a single CPU core without lock contention or context switching.
2. Incremental Hash Resizing (Rehash)
When Redis hash tables expand, dict entries migrate incrementally across background requests to avoid blocking the main event thread.
3. Persistence Modes
- RDB (Snapshotting): Point-in-time binary snapshot saved to disk at configured intervals.
- AOF (Append-Only File): Logs every write command sequentially. Recovered by replaying log records.
Redis 6+ introduced multi-threading exclusively for offloading network socket I/O parsing, while core command execution remains single-threaded.
Key Architectural Comparison
| Redis Component | Architectural Mechanism | Technical Benefit |
|---|---|---|
| I/O Multiplexing | Non-blocking Linux epoll event loop. | Single thread handles 100k+ concurrent client sockets without thread contention. |
| Dynamic Resizing (Rehash) | Progressive incremental rehashing across requests. | Zero latency freezing when expanding hash table buckets. |
| Persistence (AOF vs RDB) | Sequential disk append vs fork-based memory snapshots. | Fast recovery time with sub-second durability guarantees. |