Build Your Own Redis Challenge
I’ve found ‘Build Your Own X’ tutorials to be a very effective way of improving my understanding of tools we use everyday, like Git, Docker, Redis etc.
What I cannot create, I cannot understand
- Richard Feynman
The problem with many of these tutorials is that they aren’t interactive. It’s okay when tutorials are small, but as they grow in size it can get very hard to follow.
I wish there was a HackerRank-like product where I could, over time, complete ~20 steps and build a large-ish program, while receiving constant TDD-style feedback. This could also be used as a recruiting tool.
This ‘Build Your Own Redis’ challenge is an attempt at such a product. It serves as a code-along challenge for my ‘Build Your Own Redis’ series.
How it works
You start out by cloning a repo that has a basic ‘Hello World’ scaffolding for your
language, and a
tester utility that guides you through the challenge.
make test the first time, and you’re presented with something like this:
The tester attempted to connect to Redis’s default port (
6379), but wasn’t able to.
Once you’ve written the code to start a server on
6379, tests for the first
stage are green.
Now you can proceed to the next step:
You can also choose to report results to a leaderboard:
(Thanks to @jayantbh for the gorgeous UI!)
Redis Challenge Stages
The Redis challenge has multiple stages.
Stage 0: Bind to a port
Spawn a TCP server that binds to Redis’s default port and accepts connections from clients.
Stage 1: PING <-> PONG
Respond to a
PING command. You’ll need to
reply using the Redis Protocol.
Stage 2: ECHO… O… O…
Respond to an
ECHO command. In stage 1, you
didn’t really have to parse what the user sent you, but in this stage you
will. Time to parse RESP!
Stage 3: Multiple Clients
Handle multiple clients at once.
Resist the temptation to use multiple threads. Do this using a single thread (like the original Redis does!). Hint: Build an event loop using select.
Stage 4: SET & GET
Implement SET and GET. Your server must now be capable of holding state!
Stage 5: Expiry!
There’s a flag in SET that allows a client to set an expiry on a key. Find it, and add it to your Redis implementation.
Note: Contact me if you’d like to suggest next stages.
How do I try this out?
Clone one of these repos:
- Redis Challenge Starter - Haskell
- Redis Challenge Starter - Go
- Redis Challenge Starter - Python
- Redis Challenge Starter - ReasonML
(If you’d like to attempt this in a different language, do let me know!)
Follow the instructions in
README.md. If you’d like to be part of a
leaderboard, contact me for an API key.