r/PythonLearning • u/Owlbuddy121 • Feb 25 '26
If Redis is single-threaded, how does it actually hit millions of RPS?
I’ve been diving into Redis architecture lately, and the "single-threaded" nature of it feels like a paradox when you look at its performance benchmarks.
I understand that it avoids context switching and lock contention, but I’m struggling to visualize how it handles massive concurrency without getting choked by a few heavy requests. Is it all down to the event loop (IO multiplexing), or is there more "magic" happening under the hood with how it handles memory?
Would love a breakdown of why this design choice actually makes it faster rather than being a bottleneck.
1
u/nuclearmeltdown2015 Feb 26 '26
Damn I feel like I am on pre COVID again seeing questions like this pop up.
1
1
u/_gianlucag_ Feb 27 '26 edited Feb 27 '26
Multi threading makes sense when you want to perform multiple expensive tasks at the same time. Or the same task as parallel instances of it. If the task is trivial, there's little to no gain in multithreading, and you are better of with a single thread "roundrobin-ing" over the jobs.
In Redis, the real bottleneck is not the cpu, but the I/O. Redis is an in-memory data store, the cpu tasks are extremely simple and short. Consuming a huge list of such simple tasks using a single thread is much more efficient than orchestrating multiple threads over the list (due to synchronization overhead).
1
u/mmacvicarprett Feb 28 '26
I do not think you will realistically get in the millions of qps without getting into cluster mode. I normally see tenths of thousands, probably can get in the hundreds on a very good machine and simple operations.
2
0
Feb 25 '26
[deleted]
1
u/Swimming-Diet5457 Feb 26 '26
I think that for redis is not really tha case, it is REALLY only 1 thread, just iterating over a eterogenic queue of commands
9
u/Waste_Grapefruit_339 Feb 25 '26
Great question - this seems paradoxical at first, but the key is that Redis isn't "single-threaded" in the way people usually imagine.
The command execution loop itself is single-threaded, yes. But that actually makes it fast, not slow, because it avoids locks, thread contention, and context switching overhead. Instead of multiple threads fighting over shared memory, one thread processes commands sequentially - which is extremely efficient when each command is very small and fast (which Redis commands usually are).
The real reason it can handle millions of requests/sec is:
I/O is multiplexed (epoll/kqueue/select), so one thread can manage thousands of connections
operations are in-memory -> no disk latency
commands are intentionally simple and atomic
network + kernel do a lot of the heavy lifting
newer Redis versions even offload some I/O to background threads
So the trick is: single-threaded execution + non-blocking I/O + in-memory data = extremely high throughput.
It's less "magic" and more "carefully constrained design."