Loading...

Build your own Redis

Learn about TCP servers, the Redis protocol and more

Start Building
redis
C
redis
C++
redis
Gleam
redis
Scala
redis
OCaml
redis
Zig
redis
Kotlin
redis
Odin
redis
Clojure
redis
Crystal
redis
C#
redis
Elixir
redis
Go
redis
Haskell
redis
Java
redis
JavaScript
redis
PHP
redis
Python
redis
Ruby
redis
Rust
redis
TypeScript

This challenge requires a CodeCrafters Membership.

You're welcome to study the full challenge structure and stage instructions for free. A membership is needed for submitting code and viewing solutions.

Want to try a free challenge? Try Build your own Shell — it's free this month.

Redis is an in-memory data structure store often used as a database, cache, message broker and streaming engine. In this challenge you'll build your own Redis server that is capable of serving basic commands, reading RDB files and more.

Along the way, you'll learn about TCP servers, the Redis Protocol and more.

What exactly will I build?
What exactly will I learn?
Why should I build such a project?
What are the prerequisites for this challenge?

Base Stages

Redis is an in-memory data structure store often used as a database, cache, message broker and streaming engine. In this challenge you'll build your own Redis server that is capable of serving basic commands, reading RDB files and more.

Along the way, you'll learn about TCP servers, the Redis Protocol and more.

Bind to a port
Very easy
We'd expect a proficient developer to take < 5 minutes to complete this stage.
Respond to PING
Easy
We'd expect a proficient developer to take 5-10 minutes to complete this stage.
Respond to multiple PINGs
Easy
We'd expect a proficient developer to take 5-10 minutes to complete this stage.
Handle concurrent clients
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Implement the ECHO command
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Implement the SET & GET commands
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Expiry
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.

Lists

In this challenge extension you'll add support for Lists to your Redis implementation.

Along the way, you'll learn commands like RPUSH, LRANGE, and more.

Create a list
Easy
We'd expect a proficient developer to take 5-10 minutes to complete this stage.
Append an element
Easy
We'd expect a proficient developer to take 5-10 minutes to complete this stage.
Append multiple elements
Easy
We'd expect a proficient developer to take 5-10 minutes to complete this stage.
List elements (positive indexes)
Easy
We'd expect a proficient developer to take 5-10 minutes to complete this stage.
List elements (negative indexes)
Easy
We'd expect a proficient developer to take 5-10 minutes to complete this stage.
Prepend elements
Easy
We'd expect a proficient developer to take 5-10 minutes to complete this stage.
Query list length
Easy
We'd expect a proficient developer to take 5-10 minutes to complete this stage.
Remove an element
Easy
We'd expect a proficient developer to take 5-10 minutes to complete this stage.
Remove multiple elements
Easy
We'd expect a proficient developer to take 5-10 minutes to complete this stage.
Blocking retrieval
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Blocking retrieval with timeout
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.

Streams

In this challenge extension you'll add support for the Stream data type to your Redis implementation.

Along the way you'll learn about commands like XADD, XRANGE and more.

The TYPE command
Easy
We'd expect a proficient developer to take 5-10 minutes to complete this stage.
Create a stream
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Validating entry IDs
Easy
We'd expect a proficient developer to take 5-10 minutes to complete this stage.
Partially auto-generated IDs
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Fully auto-generated IDs
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Query entries from stream
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Query with -
Easy
We'd expect a proficient developer to take 5-10 minutes to complete this stage.
Query with +
Easy
We'd expect a proficient developer to take 5-10 minutes to complete this stage.
Query single stream using XREAD
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Query multiple streams using XREAD
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Blocking reads
Hard
We'd expect a proficient developer to take more than 1 hour to complete this stage.
Blocking reads without timeout
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Blocking reads using $
Easy
We'd expect a proficient developer to take 5-10 minutes to complete this stage.

Transactions

In this challenge extension you'll add support for Transactions to your Redis implementation.

Along the way, you'll learn about the MULTI, EXEC, and DISCARD commands, as well as how Redis handles transactions atomically.

The INCR command (1/3)
Easy
We'd expect a proficient developer to take 5-10 minutes to complete this stage.
The INCR command (2/3)
Easy
We'd expect a proficient developer to take 5-10 minutes to complete this stage.
The INCR command (3/3)
Easy
We'd expect a proficient developer to take 5-10 minutes to complete this stage.
The MULTI command
Easy
We'd expect a proficient developer to take 5-10 minutes to complete this stage.
The EXEC command
Easy
We'd expect a proficient developer to take 5-10 minutes to complete this stage.
Empty transaction
Hard
We'd expect a proficient developer to take more than 1 hour to complete this stage.
Queueing commands
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Executing a transaction
Hard
We'd expect a proficient developer to take more than 1 hour to complete this stage.
The DISCARD command
Easy
We'd expect a proficient developer to take 5-10 minutes to complete this stage.
Failures within transactions
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Multiple transactions
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.

Replication

In this challenge extension you'll add support for Replication to your Redis implementation.

Along the way you'll learn about how Redis's leader-follower replication works, the PSYNC command and more.

Configure listening port
Easy
We'd expect a proficient developer to take 5-10 minutes to complete this stage.
The INFO command
Easy
We'd expect a proficient developer to take 5-10 minutes to complete this stage.
The INFO command on a replica
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Initial replication ID and offset
Easy
We'd expect a proficient developer to take 5-10 minutes to complete this stage.
Send handshake (1/3)
Easy
We'd expect a proficient developer to take 5-10 minutes to complete this stage.
Send handshake (2/3)
Easy
We'd expect a proficient developer to take 5-10 minutes to complete this stage.
Send handshake (3/3)
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Receive handshake (1/2)
Easy
We'd expect a proficient developer to take 5-10 minutes to complete this stage.
Receive handshake (2/2)
Easy
We'd expect a proficient developer to take 5-10 minutes to complete this stage.
Empty RDB transfer
Easy
We'd expect a proficient developer to take 5-10 minutes to complete this stage.
Single-replica propagation
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Multi-replica propagation
Hard
We'd expect a proficient developer to take more than 1 hour to complete this stage.
Command processing
Hard
We'd expect a proficient developer to take more than 1 hour to complete this stage.
ACKs with no commands
Easy
We'd expect a proficient developer to take 5-10 minutes to complete this stage.
ACKs with commands
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
WAIT with no replicas
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
WAIT with no commands
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
WAIT with multiple commands
Hard
We'd expect a proficient developer to take more than 1 hour to complete this stage.

RDB Persistence

In this challenge extension you'll add persistence support to your Redis implementation.

Along the way you'll learn about Redis's RDB file format and more.

RDB file config
Easy
We'd expect a proficient developer to take 5-10 minutes to complete this stage.
Read a key
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Read a string value
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Read multiple keys
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Read multiple string values
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Read value with expiry
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.

Pub/Sub

In this challenge extension you'll add support for Publish/Subscribe (Pub/Sub) to your Redis implementation.

Along the way, you'll learn commands like SUBSCRIBE, PUBLISH, and more.

Subscribe to a channel
Easy
We'd expect a proficient developer to take 5-10 minutes to complete this stage.
Subscribe to multiple channels
Easy
We'd expect a proficient developer to take 5-10 minutes to complete this stage.
Enter subscribed mode
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
PING in subscribed mode
Easy
We'd expect a proficient developer to take 5-10 minutes to complete this stage.
Publish a message
Easy
We'd expect a proficient developer to take 5-10 minutes to complete this stage.
Deliver messages
Hard
We'd expect a proficient developer to take more than 1 hour to complete this stage.
Unsubscribe
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.

Sorted Sets

In this challenge extension you'll add support for Sorted Sets (zsets) to your Redis implementation.

Along the way, you'll learn commands like ZADD, ZRANGE, and more.

Create a sorted set
Easy
We'd expect a proficient developer to take 5-10 minutes to complete this stage.
Add members
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Retrieve member rank
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
List sorted set members
Easy
We'd expect a proficient developer to take 5-10 minutes to complete this stage.
ZRANGE with negative indexes
Easy
We'd expect a proficient developer to take 5-10 minutes to complete this stage.
Count sorted set members
Easy
We'd expect a proficient developer to take 5-10 minutes to complete this stage.
Retrieve member score
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Remove a member
Easy
We'd expect a proficient developer to take 5-10 minutes to complete this stage.

Geospatial Commands

In this challenge extension you'll add support for Geospatial Commands to your Redis implementation.

Along the way, you'll learn commands like GEOADD, GEOSEARCH, and more.

Respond to GEOADD
Easy
We'd expect a proficient developer to take 5-10 minutes to complete this stage.
Validate coordinates
Easy
We'd expect a proficient developer to take 5-10 minutes to complete this stage.
Store a location
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Calculate location score
Hard
We'd expect a proficient developer to take more than 1 hour to complete this stage.
Respond to GEOPOS
Easy
We'd expect a proficient developer to take 5-10 minutes to complete this stage.
Decode coordinates
Hard
We'd expect a proficient developer to take more than 1 hour to complete this stage.
Calculate distance
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Search within radius
Easy
We'd expect a proficient developer to take 5-10 minutes to complete this stage.

Authentication

In this challenge extension you'll add support for default user Authentication to your Redis implementation.

Along the way, you'll learn about commands like ACL WHOAMI, ACL GETUSER, ACL SETUSER, and AUTH, and more.

Respond to ACL WHOAMI
Easy
We'd expect a proficient developer to take 5-10 minutes to complete this stage.
Respond to ACL GETUSER
Easy
We'd expect a proficient developer to take 5-10 minutes to complete this stage.
The nopass flag
Easy
We'd expect a proficient developer to take 5-10 minutes to complete this stage.
The passwords property
Easy
We'd expect a proficient developer to take 5-10 minutes to complete this stage.
Setting default user password
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
The AUTH command
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Enforce authentication
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Authenticate using AUTH
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.