Video series · 21 parts

Building a Redis Clone in Go

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.

  1. Part 1
    Building a Redis clone in Go - Part 1 (TCP server, RESP protocol) thumbnail
    YouTube

    Building a Redis clone in Go - Part 1 (TCP server, RESP protocol)

    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.

    Watch →
  2. Part 2
    Building a Redis clone in Go - Part 2 (GET, SET, Writing to client) thumbnail
    YouTube

    Building a Redis clone in Go - Part 2 (GET, SET, Writing to client)

    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…

    Watch →
  3. Part 3
    Building a Redis clone in Go - Part 3 (Concurrent Server, Config Parser) thumbnail
    YouTube

    Building a Redis clone in Go - Part 3 (Concurrent Server, Config Parser)

    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…

    Watch →
  4. Part 4
    Building a Redis clone in Go - Part 4 (Append-only Data Persistence) thumbnail
    YouTube

    Building a Redis clone in Go - Part 4 (Append-only Data Persistence)

    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.

    Watch →
  5. Part 5
    Building a Redis clone in Go - Part 5 (RDB Data Persistence) thumbnail
    YouTube

    Building a Redis clone in Go - Part 5 (RDB Data Persistence)

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

    Watch →
  6. Part 6
    Building a Redis clone in Go - Part 6 (DEL, EXISTS, KEYS, & Concurrency) thumbnail
    YouTube

    Building a Redis clone in Go - Part 6 (DEL, EXISTS, KEYS, & Concurrency)

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

    Watch →
  7. Part 7
    Building a Redis clone in Go - Part 7 (SAVE and BGSAVE) thumbnail
    YouTube

    Building a Redis clone in Go - Part 7 (SAVE and BGSAVE)

    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…

    Watch →
  8. Part 8
    Building a Redis clone in Go - Part 8 (DBSIZE and FLUSHDB) thumbnail
    YouTube

    Building a Redis clone in Go - Part 8 (DBSIZE and FLUSHDB)

    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.

    Watch →
  9. Part 9
    Building a Redis clone in Go - Part 9 (RDB Checksum Protection) thumbnail
    YouTube

    Building a Redis clone in Go - Part 9 (RDB Checksum Protection)

    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.

    Watch →
  10. Part 10
    Building a Redis clone in Go - Part 10 (AUTH and Passwords) thumbnail
    YouTube

    Building a Redis clone in Go - Part 10 (AUTH and Passwords)

    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.

    Watch →
  11. Part 11
    Building a Redis clone in Go - Part 11 (EXPIRE and TTL) thumbnail
    YouTube

    Building a Redis clone in Go - Part 11 (EXPIRE and TTL)

    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.

    Watch →
  12. Part 12
    Building a Redis clone in Go - Part 12 (Rewriting AOF files) thumbnail
    YouTube

    Building a Redis clone in Go - Part 12 (Rewriting AOF files)

    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.

    Watch →
  13. Part 13
    Building a Redis clone in Go - Part 13 (Database Transactions) thumbnail
    YouTube

    Building a Redis clone in Go - Part 13 (Database Transactions)

    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.

    Watch →
  14. Part 14
    Building a Redis clone in Go - Part 14 (Managing Memory & Evictions) thumbnail
    YouTube

    Building a Redis clone in Go - Part 14 (Managing Memory & Evictions)

    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.

    Watch →
  15. Part 15
    Building a Redis clone in Go - Part 15 (Evicting Keys & allkeys-random eviction) thumbnail
    YouTube

    Building a Redis clone in Go - Part 15 (Evicting Keys & allkeys-random eviction)

    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.

    Watch →
  16. Part 16
    Building a Redis clone in Go - Part 16 (Fixing AOF file sync) thumbnail
    YouTube

    Building a Redis clone in Go - Part 16 (Fixing AOF file sync)

    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.

    Watch →
  17. Part 17
    Building a Redis clone in Go - Part 17 (allkeys-lru and allkeys-lfu) thumbnail
    YouTube

    Building a Redis clone in Go - Part 17 (allkeys-lru and allkeys-lfu)

    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.

    Watch →
  18. Part 18
    Building a Redis clone in Go - Part 18 (MONITOR command) thumbnail
    YouTube

    Building a Redis clone in Go - Part 18 (MONITOR command)

    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.

    Watch →
  19. Part 19
    Building a Redis clone in Go - Part 19 (INFO command) thumbnail
    YouTube

    Building a Redis clone in Go - Part 19 (INFO command)

    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.

    Watch →
  20. Part 20
    Building a Redis clone in Go - Part 20 (Finish INFO & fix AOF memory) thumbnail
    YouTube

    Building a Redis clone in Go - Part 20 (Finish INFO & fix AOF memory)

    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.

    Watch →
  21. Part 21
    Building a Redis clone in Go - Part 12-1 (Fixing rewrites) thumbnail
    YouTube

    Building a Redis clone in Go - Part 12-1 (Fixing rewrites)

    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.

    Watch →
Hassan Aziz pointing up

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.

Book a free call on Calendly