Video series · 21 parts
Build a Redis server from scratch in Go: TCP and the RESP protocol, AOF and RDB persistence, transactions, key expiry, LRU and LFU eviction, AUTH and more.

I build the first working layer of a Redis clone in Go: a TCP server on port 6379 that speaks enough RESP to parse real redis-cli commands.

I build the actual data layer of my Go Redis clone: GET and SET handlers over an in-memory map, plus a Writer abstraction that serializes my Value structs into RESP so I never hand-construct plus signs and CRLF pairs…

I add concurrency to my Go Redis clone by wrapping the store in a sync.RWMutex — ReadLock for GET, Lock for SET — so multiple clients can hit the same commands without race conditions, then build a parser for a minimal…

I implement append-only file persistence for my Redis clone in Go, showing how Redis can durably replay SET commands from disk instead of relying only on in-memory state.

I implement RDB data persistence for my Go Redis clone by snapshotting the in-memory store to disk and reloading it on server start.

I fix the concurrency bug that crashed my Go Redis server the moment a client disconnected, then implement the DEL, EXISTS, and KEYS commands.

I implement the SAVE and BGSAVE commands in my Go Redis clone, after tightening the RDB layer: a read lock in saveRDB so snapshots don't race with writes, an os.O_TRUNC flag so every save overwrites stale data, os.Open…

I implement the DBSIZE and FLUSHDB commands in my Go Redis clone, and I show why the obvious way to flush a database is the wrong one.

I add SHA-256 checksum protection to the RDB save path in my Go Redis clone so a snapshot is only considered successfully written when the in-memory buffer and on-disk file hashes match.

I implement AUTH and password protection for my Go Redis clone by adding a requirepass directive, tracking authentication state per client, and blocking unauthenticated commands.

EXPIRE and TTL need each key to carry its own expiry timestamp, so I change the store from a map of strings to a map of *Key structs holding the value and an expiry time.Time, then fix every handler that breaks.

I build the BGREWRITEAOF command for my Go Redis clone so the append-only file stops replaying outdated SET commands and keeps only the latest value for each key.

I implement Redis-style database transactions in my Go Redis clone, adding MULTI, EXEC, and DISCARD command handlers and a transaction queue that holds commands until execution.

I add real memory management to my Go Redis clone: every key now reports its approximate footprint, and the server refuses writes once it hits a configured max-memory limit.

I implement the allkeys-random eviction policy for my Go Redis clone by sampling a bounded set of keys and deleting until memory is freed.

I fix AOF file sync in my Go Redis clone by making every array read share one buffered reader instead of creating a fresh reader each time, which was causing replay to restore only the first key.

I implement Redis's allkeys-lru and allkeys-lfu eviction policies in my Go Redis clone by sorting sampled keys with the metadata already stored on each item, then reusing my evict-until-memory-freed loop.

I fix a missing mutex unlock bug in my Go Redis clone, refactor the code into focused files, and then implement the MONITOR command so one client can receive every command other clients run.

The INFO command is the last major piece of my Redis clone, and in this part I build out the server, client, and memory sections of its response.

I finish the INFO command by wiring up the persistence and general categories, then fix an AOF bug where restoring the append-only file ignored the server's memory limit.

I fix a missing step in my Go Redis clone's BGREWRITEAOF flow: commands that arrive during the rewrite are buffered, but I never flushed that buffer back into the AOF file afterward, so those commands could be lost.


Dude, you’re at the bottom of my landing page.
Just book a call already if you’re that interested.
You scrolled all the way here.