Video in progress

People say Redis is single-threaded. What does that mean, and why is it still fast?

Commands run one after another on a single main thread. The data is in RAM, commands are very short and no locks are needed, so one thread handles hundreds of thousands of operations per second.

📖 Answer

Redis is built around an event loop: one thread watches thousands of connections and runs incoming commands sequentially. Two important consequences follow.

The good side: every command is atomic. Nobody else can interleave inside INCR, LPUSH or SADD, so you don't think about synchronization.

The bad side: one slow command makes everyone wait. If you send LRANGE 0 -1 on a list with a million elements, or KEYS *, all other clients stand in line for that whole time.

To be precise: since Redis 6, extra I/O threads can be enabled for reading from and writing to the network, and background work like persistence and UNLINK runs separately. But the commands themselves still run on a single thread.