Project-based advanced 15 lessons 45-60 hours updated 3 Dec 2026

Build a Key-Value Database in Go: From Scratch to Production

Build a key-value database in Go from scratch: hash maps, WAL, LSM trees and SSTables, a RESP TCP server, transactions, replication and production ops.

Written and tested by AlgoSimplified

What you'll learn

  • Design a key-value store's architecture, API and on-disk layout
  • Make it thread-safe with mutexes, RWMutex, sharded locks and atomics
  • Guarantee durability with a checksummed write-ahead log and crash recovery
  • Build an LSM tree: skip-list memtable, SSTables, Bloom filters and compaction
  • Serve clients over TCP with the Redis protocol (RESP) and a pooled Go client
  • Add MVCC transactions with snapshot isolation and conflict detection
  • Replicate data leader-to-follower with failover and lag monitoring
  • Run it in production: metrics, profiling, Docker, Kubernetes, TLS and auth

// learning roadmap

Course content

5 modules · 15 lessons · 45-60 hours

  1. 01 Foundation & Data Structures Introduction & database fundamentals · Core data structures
    1. Lesson 1: Introduction & database fundamentals What a key-value store is, when to use one, and how to plan the architecture, project layout and milestones of the Go key-value database in this course. 2-3 hours
    2. Lesson 2: Core data structures Pick the core data structure for a Go key-value store: hash maps, hash functions and value serialization, built test-first with Go tests and benchmarks. 3-4 hours
  2. 02 Storage & Concurrency Concurrency & thread safety · Write-ahead log · SSTables & LSM trees · Compaction & optimization
    1. Lesson 3: Concurrency & thread safety Make a Go key-value store thread-safe: race conditions, Mutex vs RWMutex vs atomic, sharded locks for high concurrency, deadlocks and lock-free ideas. 3-4 hours
    2. Lesson 4: Write-ahead log (WAL) Build a write-ahead log (WAL) in Go: why an append-only log gives durability, binary records, checksums, corruption detection, crash recovery, rotation. 3-4 hours
    3. Lesson 5: SSTables & LSM trees LSM trees in Go: skip-list memtables, writing sorted string tables (SSTables) to disk, dual memtables for concurrent writes and background flushing. 4-5 hours
    4. Lesson 6: Compaction & optimization LSM-tree compaction in Go: size-tiered vs leveled strategies, Bloom filters for fast negative lookups, block caching, compression and throttling. 3-4 hours
  3. 03 Networking & Client TCP server & protocol · Client library & networking
    1. Lesson 7: TCP server & protocol Put your Go database on the network: protocol design, the Redis protocol (RESP) implemented from scratch, and a TCP server for concurrent connections. 3-4 hours
    2. Lesson 8: Client library & networking Write a Go client library for your database: connection pooling, retries with exponential backoff, circuit breakers, pipelining and timeout handling. 3-4 hours
  4. 04 Advanced Database Features Transactions & ACID · Replication & availability
    1. Lesson 9: Transactions & ACID Transactions and ACID in a Go key-value store: isolation levels, MVCC, snapshot isolation, write-conflict detection and deadlock prevention. 4-5 hours
    2. Lesson 10: Replication & availability Leader-follower replication in Go: consistency models, replication lag, health checks, automatic failover, leader election and split-brain handling. 4-5 hours
  5. 05 Production & Operations Monitoring & observability · Performance tuning · Deployment & configuration · Security & hardening · Capstone & beyond
    1. Lesson 11: Monitoring & observability Monitor a Go database in production: Prometheus metrics, structured logging with zap, profiling, health checks and the four golden signals. 2-3 hours
    2. Lesson 12: Performance tuning Performance tuning for a Go database: finding bottlenecks with pprof, cutting allocations with object pools, load testing and capacity planning. 3-4 hours
    3. Lesson 13: Deployment & configuration Deploy a Go database: configuration with YAML, TOML and env vars, Docker and Docker Compose, Kubernetes manifests, backups and graceful shutdown. 2-3 hours
    4. Lesson 14: Security & hardening Secure a Go database server: TLS encryption, password and token authentication, authorization and access control, rate limiting and hardening defaults. 2-3 hours
    5. Lesson 15: Capstone & beyond Capstone for the Go key-value database: add TTL expiry, pub/sub, Lua scripting and geo queries, then write API docs and an operational runbook. 4-5 hours

Who this course is for

  • Backend engineers who want to know how databases work inside
  • Go developers looking for a serious systems project for their portfolio
  • Anyone who wants storage internals to stop being a black box, at work or in an interview

Before you start

  • Comfortable writing non-trivial Go programs
  • Basic data structures (hash maps, trees, linked lists)
  • Familiarity with the Go standard library and go test

About this course

Why build a database?

Because most backend bugs you will debug later come from not knowing what the storage layer does with your write. After this course, “fsync”, “compaction”, “replication lag” and “snapshot isolation” stop being words in a postmortem and become code you have written and broken yourself.

How the course works

Each lesson adds one layer to the same Go codebase: an in-memory map, then locking, then a write-ahead log, an LSM engine, a network server, transactions, replication and operations. Most lessons end with a lab that has starter code with TODOs, hints, and a reference solution that passes go test -race. It is long (45 to 60 hours); the first six lessons alone give you a working, crash-safe storage engine.

The ideas carry over to systems you will run. Kafka stores each partition as an append-only log split into segments and compacts it by key, which is close to what you build in the write-ahead log and compaction lessons; how Kafka stores data shows the production version.

Questions

Is this course free?

Yes. All 15 lessons are free to read, with no account and no paywall partway through.

How is my progress saved?

In your browser (localStorage). Mark a lesson complete at the bottom of the page and the course page, sidebar and Continue button pick it up. Clearing site data or switching devices resets it.

How long does it take?

About 45-60 hours of reading and coding. At an hour a day that is roughly 6 to 9 weeks; skimming the parts you already know is fine.

What should I know first?

Comfortable writing non-trivial Go programs. Basic data structures (hash maps, trees, linked lists). Familiarity with the Go standard library and go test.