Video series · 21 parts

Building a Redis Clone in Go

A from-scratch Redis server in Go: a TCP server and the RESP protocol, AOF and RDB persistence, transactions, key expiry, memory eviction (LRU, LFU, random), AUTH, MONITOR and INFO.

  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 a Redis clone in Go from scratch, starting with a TCP server on port 6379 and a parser for RESP, the Redis Serialization Protocol. I install Redis to get the official redis-cli, stop the bundled Redis server…

    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 recap RESP and then build the GET and SET command handlers plus the client reply writer for my Go Redis clone, turning the server into a working in-memory key-value store. I go through RESP's core types: + for simple…

    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 support to my Go Redis clone with a read-write mutex and build a minimal redis.conf parser that will drive data persistence. I replace the bare map with a Database struct that holds the store and a…

    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 (AOF) persistence for my Go Redis clone in Part 4, comparing Redis's AOF and RDB approaches and building the AOF side. I record every SET command as a RESP array in backup.aof using the…

    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 build RDB data persistence into my Go Redis clone by snapshotting the whole in-memory store to disk and loading it back on server start. I set up snapshot trackers backed by time.Ticker so each configured save rule…

    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 my Go Redis clone’s concurrency model and implement the DEL, EXISTS, and KEYS commands. I move connection acceptance into an infinite loop, handle each client in its own goroutine with a WaitGroup, and close…

    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 up the RDB snapshot code and fixing concurrency and file-handling bugs. I add a read lock around RDB encoding, switch the save file to…

    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, showing how to return the number of keys and wipe the entire database safely. For DBSIZE, I take a read lock and return the length of the in-memory map…

    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 my Go Redis clone's RDB save path so every snapshot is verified against what actually lands on disk. I encode the database into an in-memory buffer, hash it, write the bytes, flush…

    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 in my Go Redis clone by adding requirepass, tracking per-client authentication, and blocking unauthenticated commands. I add requirepass dolphins to the config, parse it into a…

    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)

    I build the EXPIRE and TTL commands into my Go Redis clone by refactoring the database store from map[string]string to map[string]*Key, where each key holds its value and an expiry time.Time. I add database-level Set…

    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, which compacts an append-only file by replacing old, outdated SET commands with only the latest key values. I demonstrate the problem by setting the same key to…

    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 by adding MULTI, EXEC, and DISCARD command handlers. I add a transaction struct to the app state, queue commands inside the handle function after…

    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 approximate memory tracking and a maxmemory limit to my Go Redis clone, then enforce a no-eviction policy that rejects writes when the server runs out of memory. I calculate each key's approximate usage by adding…

    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: when the database is out of memory, I sample a configurable number of keys and delete them until enough memory is freed for the new write. I add…

    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 the AOF restore bug in my Go Redis clone where the server only loaded the first key from the append-only file and ignored every command after it. The root cause was that readArray created a fresh bufio.Reader for…

    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 the allkeys-lru and allkeys-lfu eviction policies in my Go Redis clone by sorting the sampled keys by last access time for LRU or access count for LFU, then calling evictUntilMemoryFree until enough memory…

    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 in the GET path of my Go Redis clone, refactor the growing codebase into focused files, and implement the MONITOR command so one client can observe every command other clients run. Along…

    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)

    I build out the INFO command for my Go Redis clone, adding the server, clients, and memory sections while leaving persistence and general stats for the final part. I create an Info struct and a build method that pulls…

    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 and fix AOF memory handling in my Go Redis clone, wrapping up the 20-part series. I add the persistence and general INFO categories, which means tracking RDB last-save time and save count, AOF…

    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 an AOF rewrite bug in my Go Redis clone where commands buffered during BGREWRITEAOF were never flushed to the rewritten file. A viewer caught that after the rewrite clears and rebuilds the AOF, any new commands…

    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.