Course contentsShow
← System Design
Lesson 348 of 1,91910. NoSQL: Key-Value StoresFree lesson

Redis Single-Threaded Architecture

Why Redis uses a single-threaded event loop and how it achieves high performance through I/O multiplexing.

Redis Single-Threaded Architecture

What you'll learn: How Redis achieves exceptional speed using a single-threaded event loop instead of multiple threads.

The Surprising Power of One Thread

Redis handles all client commands using a single thread for execution. This might sound limiting—after all, modern servers have multiple CPU cores—but Redis turns this into a performance advantage. By avoiding multi-threading complexity, Redis eliminates context switching overhead and the need for locks around shared data structures.

How It Works: I/O Multiplexing

Redis uses an event loop with I/O multiplexing (via select, epoll, or kqueue depending on the OS). This means one thread can monitor thousands of client connections simultaneously:

  1. Redis waits for events (incoming commands) from any connected client
  2. When data arrives, the event loop picks it up
  3. Redis executes the command completely (in microseconds)
  4. Redis moves to the next event

Think of a skilled chef working alone in a kitchen: instead of waiting idly while water boils, they prepare vegetables, check the oven, and season dishes—constantly switching between tasks efficiently without needing help.

Why This Is Fast

Since Redis keeps all data in memory (covered in your earlier "In-Memory vs Persistent Key-Value Stores" lesson), operations complete in microseconds. A single thread can process tens of thousands of operations per second because:

  • No thread synchronization overhead
  • No lock contention
  • Predictable, cache-friendly memory access patterns
  • Commands execute atomically without coordination

The Limitation

Redis cannot use multiple CPU cores for command execution. However, this rarely matters because the bottleneck is usually I/O (network or disk), not CPU. For extremely high loads, you can run multiple Redis instances (one per core).

Key Takeaway: Redis's single-threaded architecture eliminates concurrency complexity while achieving high throughput through fast in-memory operations and efficient I/O multiplexing—proving that simplicity often beats parallelism for the right workload.