Understanding Redis: Single‑Threaded vs Multi‑Threaded Architecture
This article explains how Redis operates primarily with a single‑threaded model for memory and network operations, why this design is efficient, and how recent versions introduce multi‑threaded components for network I/O, persistence, and asynchronous deletion while preserving thread safety.
Hello, I am mikechen.
Redis used a single‑threaded model before version 4.0, handling both network I/O and key‑value storage with one thread.
The reasons for using a single thread are:
1. High efficiency – a single‑threaded design simplifies development and debugging.
2. Memory‑based operations – all data resides in memory, allowing extremely fast processing (up to 100,000 requests per second).
3. I/O multiplexing – Redis uses epoll/kqueue to monitor many client connections with one thread, because most operations are pure memory accesses.
4. Avoiding context switches – a single thread eliminates unnecessary thread‑switch overhead and eliminates deadlock risks.
For Redis, the main performance bottlenecks are memory bandwidth or network bandwidth, not CPU.
Redis Multi‑Threading
Although Redis’s core remains single‑threaded, multi‑threading is employed for certain functions to improve performance.
1. Network I/O – Prior to Redis 6.0, both network I/O and command execution were single‑threaded, making network I/O the bottleneck. Starting with Redis 6.0, multiple I/O threads handle network requests, increasing parallelism.
Command execution still runs on the main thread, so thread safety is preserved.
2. Persistence – When the AOF file becomes large, Redis can fork a child process that uses multiple threads to rewrite the AOF, speeding up the operation.
3. Asynchronous deletion – Commands such as UNLINK, FLUSHALL ASYNC, and FLUSHDB ASYNC perform deletions in the background to avoid blocking.
Even with these multi‑threaded components, the core data operations remain single‑threaded.
Finally, a promotional note offers a free collection of over 300,000 Chinese characters of original content, including an "Alibaba Architect Advanced Topics" compilation and a comprehensive Java interview question set covering Java, multithreading, JVM, Spring, MySQL, Redis, Dubbo, and other middleware.
Readers interested in the collections can add the author’s WeChat with the keyword “合集” to receive the materials.
Mike Chen's Internet Architecture
Over ten years of BAT architecture experience, shared generously!
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.