Distributed Systems from Scratch (Challenge Overview)
Built a Redis-compatible in-memory data store in Java, replicating core Redis functionality including data structures, persistence, replication, transactions, and real-time messaging β all from scratch.
π§ What It Does
- Implements RESP (Redis Serialization Protocol) for communication with clients
- Supports core Redis data types: strings, lists, sorted sets, and streams
- Implements Pub/Sub, transactions, and key expiration
- Enables master-slave replication and RDB persistence loading
- Supports blocking operations and thousands of concurrent clients using Java Virtual Threads
π Key Features
- String ops (
GET
,SET
,INCR
) with optional expiration - List ops (
LPUSH
,LRANGE
,BLPOP
) - Sorted Set ops (
ZADD
,ZRANGE
,ZREM
) - Stream ops (
XADD
,XREAD
,XRANGE
) - Pub/Sub (
SUBSCRIBE
,PUBLISH
) - Replication (
PSYNC
,REPLCONF
) and transaction support (MULTI
,EXEC
) - RDB loading and time-based key expiry
- Runs using Java 21βs Project Loom (virtual threads)
ποΈ Tech Stack
- Language: Java 21
- Concurrency: Virtual threads (Project Loom),
ReentrantLock
,ConcurrentHashMap
- Networking: Custom TCP server with RESP protocol support
- Design Patterns: Command pattern, layered architecture, modular command routing
π‘ Why Itβs Interesting
- Mirrors real-world Redis behavior with protocol-level compatibility
- Explores low-level systems programming in Java
- Exercises deep knowledge of networking, concurrency, and protocol design
- Builds foundational experience in distributed system components like replication and messaging
π§ Key Learnings
- Implementing a binary protocol (RESP) and ensuring spec compliance
- Managing lightweight concurrency using Java virtual threads
- Handling blocking commands without freezing the main thread (e.g.
BLPOP
,XREAD
) - Designing a transaction-safe, multi-type in-memory database
- Building and debugging a real-time replication mechanism
β TL;DR
Recreated a Redis-compatible server from the ground up in Java, with support for advanced features like replication, streams, and transactions β all using modern Java concurrency (virtual threads).