Sibling to the Python and Go workshops. Same architectural progression, idiomatic Node.js: net.createServer, Buffer, Map, setInterval, async/await, event-driven everywhere.
| # | Step | New idea | LOC |
|---|---|---|---|
| 01 | TCP echo | net.createServer + data event | ~30 |
| 02 | RESP parser | Buffer + cursor + recursive parser | ~110 |
| 03 | GET / SET | Map + dispatch object, single-thread = no locks | ~110 |
| 04 | Expiry | Date.now() + setInterval for active sweep | ~140 |
| 05 | AOF persistence | fs.createWriteStream + readFileSync replay | ~150 |
| 06 | RDB snapshots | fs.writeFile + fs.rename, async BGSAVE | ~130 |
| 07 | Pub/Sub | Map<channel, Set>, conn.write fan-out | ~140 |
| 08 | Replication | SYNC + write streaming via net.connect | ~150 |
| 09 | Graceful shutdown | process.on(SIGTERM) + drain loop | ~110 |
| 10 | Capstone benchmark | Async worker pool, measure vs real Redis | ~110 |
Each step folder ships with:
| File | Purpose |
|---|---|
server.mjs (or bench.mjs in step 10) |
The runnable server |
README.md |
Run instructions and what's new |
GUIDE.md |
Deep-dive on the Node-specific idiom |
EXERCISES.md |
4 hands-on tasks |
- Node.js 20+ (uses
node:import scheme and parseArgs) - Optional:
redis-clifor talking to the server
git clone https://github.com/learnwithparam/build-your-own-redis-nodejs.git
cd build-your-own-redis-nodejs
make 01-tcp-echoIn another terminal:
nc localhost 6380
> hello
< hellomake 01-tcp-echo
make 02-resp-parser
make 03-get-set
make 04-expiry
make 05-aof-persistence
make 06-rdb-snapshots
make 07-pubsub
make 08-replication
make 09-graceful-shutdown
make 10-capstoneSame architecture in other languages:
Each language exposes different idioms for the same shape:
| Concept | Python | Go | Node |
|---|---|---|---|
| Concurrency | Threads (step 7+) or selectors (step 9) | Goroutines from step 1 | Event loop, single-thread |
| Shared state | dict + lock | map + sync.RWMutex | Map (no lock needed) |
| Background work | threading.Thread or asyncio | go func() | setInterval, async functions |
| BGSAVE | os.fork() with COW | Snapshot + goroutine save | async fs.writeFile |
| Graceful shutdown | signal.signal + flag | context.Context + WaitGroup | process.on(SIGTERM) + drain |
make testRuns an automated structural test suite.
MIT.