Redis from First Principles, Part 2: why Redis speaks RESP
11 Jul 2026 · 3 min read · first published on LinkedIn
TCP gives Redis a stream of bytes.
But Redis executes complete commands.
Something has to bridge that gap.
Last post, we saw that recv() doesn't return complete commands. It only returns whatever bytes happened to arrive.
That immediately raised another question:
If TCP doesn't preserve message boundaries, how does Redis know where one command ends and the next begins?
My first instinct was naive.
"Why not just split on spaces?"
SET name Shubham
Until I remembered, what if a value itself contains spaces?
SET bio "Learning Redis from scratch"
Okay. Maybe split on a newline instead?
That doesn't work either. Remember the last post? TCP might deliver:
SET bi
and then later:
o "Learning Redis from scratch"
There isn't a reliable character you can split on, because TCP doesn't know anything about your commands.
Redis solves this with a protocol called RESP and the idea is simple: instead of guessing where a command ends, every piece of data tells you exactly how long it is.
The command:
SET name Shubham
becomes:
*3
$3
SET
$4
name
$7
Shubham
Two kinds of numbers are doing the work here:
*3 says "this command has 3 parts."
Then each $n says "the next part is exactly n bytes." Before reading SET, Redis already knows to read 3 bytes. Before reading Shubham, it knows to expect 7.
No guessing. No ambiguous separators. No hoping the next recv() contains the rest.

And here's the part that connects back to Part 1: a partial read is no longer a problem. If the bytes arrive split across two recv() calls, the server isn't confused it just knows it's still waiting for N more bytes.
That flipped the question my server was asking.
Not: "Did I receive the whole command?"
But: "Have I received enough bytes yet?"
That single shift completely changed how I look at protocol design.
Takeaway
RESP isn't a strange text format. It's a contract that tells the server exactly where every piece of data begins and ends even when TCP delivers the bytes in unpredictable chunks.
Now another question appeared while implementing the server:
If one client sends half a command and then pauses where do those unfinished bytes live until the rest arrives?
That's the problem I'll explore in the next post.
Comments and corrections are open on the original post.