Redis from First Principles, Part 4: one thread, thousands of clients
25 Jul 2026 · 3 min read · first published on LinkedIn
A thousand clients are connected.
Right now maybe three have sent something. The other 997 are just sitting there, silent.
How does one thread find those three without checking all thousand?
Last post, every client got its own buffer. But that assumed the server already knew which client to read from. With thousands connected, how does it know?
The obvious idea: one thread per client. It works until you have ten thousand threads and the OS spends all its time switching between them instead of doing real work.
So, one thread then. Loop over every socket and check each one. But now you're spinning asking thousands of sockets "anything yet? anything yet?" and burning full CPU just to mostly hear "no."
Both ideas make the same mistake: the server is doing the watching.
The fix is to ask the one component that already knows the operating system.
The OS is tracking every socket anyway. So instead of checking them yourself, you hand it the whole set and say: "put me to sleep, and wake me the moment any of these has data."
One call. It sleeps on all the sockets at once, and wakes up handing you only the ones that are ready. The 997 idle clients cost nothing.
This is I/O multiplexing. My pyredis uses Python's selectors module, which grabs the most efficient version of OS(epoll on Linux).

That flipped how I saw the loop.
It stopped asking every client "do you have data?"
and started waiting for clients to raise their hand.
But here's the part that sounds wrong
If one thread handles every client, then commands run one at a time. Nothing happens in parallel. Ever.
So why is Redis famously fast?
Because for what Redis does, one thread was never the bottleneck.
The data lives in memory, so each command is a handful of nanoseconds, there's barely anything to parallelize. And a single thread has a hidden superpower: no locks, and no time lost switching between threads. Commands simply run one after another, each finishing before the next begins.
Multiplexing is what makes that thread worth it. It's never stuck waiting on a slow client, so it spends all its time actually running commands. The real limit becomes the network and memory, not the CPU and one focused thread saturates those just fine.
Single-threaded isn't the compromise. It's the design.
Takeaway
An event loop is one idea: don't poll thousands of things yourself ask the OS which few are ready, and handle only those. That's what lets a single thread stay busy enough that one is all you need.
Which points at the one limit we haven't touched.
Everything Redis is fast because of lives in memory. But memory runs out.
So what happens when it fills up and who decides what gets thrown away?
That's where we go next.
Comments and corrections are open on the original post.