Project 7: Mini Redis Clone

A Redis-compatible in-memory key-value store supporting strings, lists, hashes, sets, TTL expiration, persistence (RDB/AOF), and the Redis protocol (RESP).

Quick Reference

Attribute Value
Primary Language Go
Alternative Languages C, Rust, C++
Difficulty Level 4: Expert
Time Estimate 1 month+
Knowledge Area Data Structures, Networking, Persistence
Tooling None (from scratch)
Prerequisites Completed Projects 1-6. Strong TCP networking skills. Understanding of data structure implementation.

What You Will Build

A Redis-compatible in-memory key-value store supporting strings, lists, hashes, sets, TTL expiration, persistence (RDB/AOF), and the Redis protocol (RESP).

Why It Matters

This project builds core skills that appear repeatedly in real-world systems and tooling.

Core Challenges

  • Implementing RESP protocol → maps to binary protocol parsing
  • Thread-safe data store → maps to concurrent data structures
  • TTL expiration → maps to time-based goroutines and cleanup
  • Persistence (AOF/RDB) → maps to file I/O and serialization

Key Concepts

  • RESP protocol: Redis documentation (redis.io/topics/protocol)
  • Concurrent data structures: “Concurrency in Go” Ch. 3-4 - Katherine Cox-Buday
  • Persistence strategies: “Designing Data-Intensive Applications” Ch. 3 - Kleppmann
  • TCP server patterns: “Network Programming with Go” - Jan Newmarch

Real-World Outcome

$ ./miniredis --port 6379 --aof /var/data/redis.aof
MiniRedis server starting...
  Port: 6379
  AOF: /var/data/redis.aof (loading 1,234 commands)
Ready to accept connections

# In another terminal, use redis-cli:
$ redis-cli -p 6379

127.0.0.1:6379> SET user:1:name "Alice"
OK

127.0.0.1:6379> GET user:1:name
"Alice"

127.0.0.1:6379> SETEX session:abc 3600 "active"
OK

127.0.0.1:6379> TTL session:abc
(integer) 3599

127.0.0.1:6379> LPUSH queue:jobs "job1" "job2" "job3"
(integer) 3

127.0.0.1:6379> RPOP queue:jobs
"job1"

127.0.0.1:6379> HSET user:1 name "Alice" age "30" city "NYC"
(integer) 3

127.0.0.1:6379> HGETALL user:1
1) "name"
2) "Alice"
3) "age"
4) "30"
5) "city"
6) "NYC"

127.0.0.1:6379> INFO
# Server
miniredis_version:1.0.0
uptime_in_seconds:123
connected_clients:2
used_memory:4096

Implementation Guide

  1. Reproduce the simplest happy-path scenario.
  2. Build the smallest working version of the core feature.
  3. Add input validation and error handling.
  4. Add instrumentation/logging to confirm behavior.
  5. Refactor into clean modules with tests.

Milestones

  • Milestone 1: Minimal working program that runs end-to-end.
  • Milestone 2: Correct outputs for typical inputs.
  • Milestone 3: Robust handling of edge cases.
  • Milestone 4: Clean structure and documented usage.

Validation Checklist

  • Output matches the real-world outcome example
  • Handles invalid inputs safely
  • Provides clear errors and exit codes
  • Repeatable results across runs

References

  • Main guide: LEARN_GO_DEEP_DIVE.md
  • “Designing Data-Intensive Applications” by Martin Kleppmann