Goal
Build a Redis server and client subset on Tokio, following the official tutorial but
writing every line yourself. This is the canonical bridge from "I understand ownership"
to "I can write async Rust": every classic wall — Send bounds across .await, shared
state between tasks, cancellation — appears here in its natural habitat.
Subject: full brief & instructions
Practices
- Deep dive Rust — ownership across task boundaries,
Arc<Mutex<T>>,Send/Syncin anger, and the async model the note warns is "harder Rust". - Networking fundamentals — TCP streams, framing, and a real wire protocol (RESP).
- Cache management — you are building the world's most instructive cache server.
Milestones
- Hello Tokio. Runtime,
async fn,.await; connect to your future server's port with the stockmini-redisclient to see the target behavior. - Accept loop. TCP listener spawning a task per connection — and your first
compiler argument about what may cross into a spawned task, won via
moveand owned data. - Shared state.
GET/SETagainst anArc<Mutex<HashMap>>; learn why the lock must not be held across an.await, and shard the map when you feel like it. - Framing. A
Connectiontype reading RESP frames from a buffered stream — partial reads,BytesMutcursor management, frame-not-ready-yet as a normal state. - Channels. A client that multiplexes commands through one connection:
mpscfor requests,oneshotper response — message passing as the alternative to locks. - Select & shutdown.
select!over connection I/O and a shutdown broadcast; graceful drain, and cancellation-by-drop seen doing its quiet, occasionally surprising work.
Stretch goals
- Key expiration (
EXPIRE) withtokio::time, and pub/sub channels. - Benchmark against real Redis with
redis-benchmark; profile the gap. - Re-solve a Protohackers rung with this stack and compare the two languages' concurrency stories.
Related
- Deep dive Rust — the concept note whose
# Practicecites this. - Tokio mini-redis — subject — the stage-by-stage assignment and acceptance checks.
- Protohackers ladder — the same network-server territory under Go's model.
- Cache management — what Redis is for.