Redis from First Principles, Part 1: TCP is a byte stream, not a message stream
7 Jul 2026 · 3 min read · first published on LinkedIn
One client sends one command.
The server reads one command.
That assumption felt so obvious that I never questioned it until it started breaking my Redis implementation.
Over the next few weeks, I'll be sharing the biggest engineering lessons I learned while implementing Redis from scratch in Python. This won't be a code walkthrough it's a series about the networking and systems concepts that finally clicked once I had to build them myself.
The very first lesson completely changed how I think about sockets.
Imagine a client sends:
SET name Shubham
Seems straightforward.
So here's a question:
How many times does the server need to call recv() to read that command?
Once?
Twice?
The answer is...
TCP doesn't care.
The server might receive:
SET na
...and later:
me Shubham
Or it might receive multiple commands together in a single recv().
That's because TCP is a byte stream, not a message stream.
It guarantees that bytes arrive in order.
It does not guarantee where one application message ends and the next begins.

This realization broke one of my earliest assumptions while building Redis.
I couldn't treat the result of recv() as a complete command. The server was only receiving bytes, not commands.
Once that clicked, several Redis design decisions like RESP suddenly started making sense.
Takeaway
The first bug I fixed while building Redis wasn't really a Redis bug.
It was caused by misunderstanding what TCP actually guarantees.
That realization immediately led to another question:
If TCP only delivers a stream of bytes, how does Redis know where one command ends and the next begins?
That's the problem I'll explore in the next post, where I'll dive into why Redis uses the RESP protocol.
If you've ever built a TCP server, what networking concept changed the way you think about backend systems?
Comments and corrections are open on the original post.