Redis from First Principles, Part 3: where does half a command live?
17 Jul 2026 · 3 min read · first published on LinkedIn
Half a command just arrived.
The other half might show up in 2 milliseconds. Or never.
What does your server do with the half it's holding?
Last post, RESP solved one problem: the server could finally tell where a command ended.
But that immediately created another one.
A client sends:
SET name Shubham
RESP tells the server exactly how many bytes to expect. Great.
Now TCP delivers only this much:
SET na
The rest hasn't arrived. So what should the server do?
Throw an error? Start over?
Or sit in a loop calling recv() until the rest shows up?
That last one is tempting, and it's the trap. Blocking on one client until its command completes means every other connected client waits too. One slow sender freezes the whole server.
The right answer is stranger: take the bytes that did arrive, put them somewhere, and go do something else.
Which raises the real question where is somewhere?
Every connection owns its own buffer
Think of it as a small workspace attached to each client. Bytes arrive, Redis appends them to that client's buffer, and then asks one question: is there enough here to parse a complete command yet?
If yes, execute it. If no, nothing is lost. The bytes just sit there until more arrive.
And it works in the other direction too. If recv() hands back two commands glued together, the server parses the first and the leftover bytes stay in the buffer, waiting to become the start of the next command.
Under-read, over-read same buffer, same answer.

That changed how I think about TCP servers.
A connection isn't just a socket. It's also state.
Without that state, the server would have to forget everything it had already received every time recv() returned a partial command.
(This is also why real Redis caps buffer sizes. A client that promises 500MB and then goes quiet would otherwise hold that memory hostage forever. Unbounded buffers are a denial-of-service waiting to happen.)
Takeaway
RESP answers: "How do I know when a command is complete?"
Connection buffers answer: "What do I do until it becomes complete?"
Two different problems. Two different layers.
And this isn't a Redis idea. Every HTTP server, every proxy, every message broker built on TCP keeps per-connection state for exactly this reason. The moment your transport can hand you half a message, you need somewhere to put the half.
Which leads to the next question:
If every client has its own buffer, how does one thread keep track of thousands of clients without blocking on any single one of them?
That's where Redis's event loop starts to make sense.
Comments and corrections are open on the original post.