Skip to content
System design · Chapter 1 of 21 Preface

Preface

System design is usually learned at the whiteboard. A box for the load balancer, a cylinder for the database, an arrow to the cache, and the sentence “then it scales horizontally”. Whether it does, nobody at the whiteboard ever finds out. How much a cache really brings, what a replica costs for reads, when a retry hurts instead of helps: these are questions a measurement can answer, but they are rarely measured.

This course builds the system that otherwise lives on the whiteboard. On three Linux VMs, a URL shortener called kurz grows from a single instance into a distributed system: load balancer, two instances, cache, database with replica, queue, rate limiting, timeouts, failover. Each building block is added only when a measurement shows that it is missing, and each one is deliberately broken once. Every day ends with numbers: requests per second, p95, error rate.

You write the source code of kurz yourself, in Go, file by file in the book. It stays small enough to understand completely: just under 600 lines at the end, plus a counter with around 100. If you do not know Go, you can type the code and read the explanations. This is not a programming course; it is about the decisions behind the code.

The book is for developers, platform and DevOps engineers, and anyone who designs or operates systems or is preparing for a system design interview. You should know Linux in the terminal, SSH, systemctl and some SQL. You do not need a cloud: everything runs on self-managed VMs, and every building block is open source.

How the book works

  • One day, one topic. Each day has a goal, a time estimate, a short briefing and 5–8 drills. You type every command yourself and compare with “Expected”.
  • Measure instead of claim. k6 generates load on almost every day, before and after. A decision counts only when the number backs it up. Where a measurement showed something other than expected, the book says so.
  • Breaking things is part of it. Instances die, networks swallow packets, the cache fills up, the database fails. Only then does it show whether a design holds.
  • No helper scripts. Every step is shown as a single command, code and configuration as heredocs, including the checkpoint at the end of each day.
  • Where the command runs is stated in the first line of each code block: # on s1, # on s2 or # on s3.
  • Speed Drills, Checkpoint, Challenge, Interview Note, Enterprise Note close every day. The challenge is a task without instructions, with a hint and a solution. The interview note says how to explain the topic of the day in a job interview; the enterprise note says what is different in large environments.

At the end:

  • Competition (Day 16): an evening with load and five incidents, against the clock and with the measurement as proof.
  • Appendix A is the cheat sheet: the path of a request, commands, measured figures and the traps from the book. Appendix B is the final exam with ten tasks. Appendix C works through five classic interview tasks, from the URL shortener to the distributed key-value store.

The days at a glance

Day Topic Duration
0 The training ground: PostgreSQL, Valkey, NATS, HAProxy, k6 approx. 75 min
1 The app and the first measurement approx. 75 min
2 Measuring properly: percentiles, Little’s Law, saturation approx. 75 min
3 Scaling horizontally with HAProxy approx. 75 min
4 Failures at the load balancer approx. 75 min
5 Caching with Valkey approx. 75 min
6 When the cache causes trouble approx. 75 min
7 The database as a bottleneck approx. 90 min
8 Read replicas and replication lag approx. 90 min
9 IDs and sharding approx. 90 min
10 Asynchronous with NATS approx. 90 min
11 Reliable delivery: idempotency, retries, backoff approx. 90 min
12 Rate limiting and backpressure approx. 90 min
13 Timeouts, circuit breakers, cascading failures approx. 90 min
14 Consistency and CAP by example approx. 90 min
15 Estimating capacity and the design document approx. 75 min
16 Competition: the overloaded system approx. 90 min

Time: Days 0 to 15 add up to 22 hours (1320 minutes); the competition and the final exam add one and a half and two hours, a good 25 hours in total. With one training day per evening and five evenings per week, you are through in three and a half weeks.

The training ground

VM Role IP in the book In the lab
s1 HAProxy, kurz instance 1, k6, Go, workstation 172.16.0.126 4 vCPU, 11 GiB
s2 kurz instance 2, PostgreSQL replica, NATS with JetStream 172.16.0.228 2 vCPU, 3.8 GiB
s3 PostgreSQL primary, PgBouncer, Valkey 172.16.0.83 2 vCPU, 3.8 GiB
  • All VMs run Ubuntu 24.04 with SSH access and sudo, in a shared network. On Day 14 you need a free address in the same network as a virtual IP, in the book 172.16.0.11.
  • Internet access from the VMs for packages, Go modules and downloads from the official release pages.
  • The measured values depend on this hardware. More cores shift the limits; the direction of the results stays the same. So that bottlenecks become visible, each kurz instance gets only half a core from Day 3 on.
  • A snapshot of all VMs after Day 0 saves you an evening if things go wrong.

Proxmox, VMware, a cloud or Multipass, it does not matter. On a Mac with Apple Silicon, Multipass VMs are arm64. All downloads detect the architecture themselves (ARCH=$(dpkg --print-architecture)). The outputs in the book come from amd64.

Versions

Component Version
Go 1.27.4
HAProxy 3.2.27 (LTS)
PostgreSQL 18.7
PgBouncer 1.26.1 (from Day 7)
Valkey 9.2.0
NATS Server / natscli 2.15.3 / 0.5.2
k6 2.4.0
keepalived 2.2.8 (Day 14)
pgx / valkey-go / nats.go v5.13.0 / v1.0.80 / v1.56.0

What you can do afterwards

  • Generate and read load properly: open versus closed model, percentiles, Little’s Law, the point of saturation.
  • Scale a service horizontally and configure the load balancer so that nobody notices failures and deployments.
  • Add a cache, measure its hit rate and master the typical problems: cold start, simultaneous expiry, outage, stale entries.
  • Take load off the database: pool connections, use replicas for reads, measure lag, plan sharding.
  • Make work asynchronous and still count every message exactly once.
  • Make retries safe with idempotency keys, backoff and jitter.
  • Protect a system from overload: quotas, load shedding, timeouts, circuit breakers.
  • Weigh consistency against availability and carry out a failover by hand, including reconciliation after a split brain.
  • Estimate capacity with your own measurements and write a design document that others understand.
  • In the interview, not just draw boxes, but say what you measured.

What was tested

All commands and outputs come from real runs on the described training ground in November 2026, shortened where it makes sense. Measured values vary from run to run. Codes, process IDs, times and numbers will differ for you; the order of magnitude should match.

Hint: This course is an independent practice course. PostgreSQL is a trademark of the PostgreSQL Community Association. Valkey is a project of the Linux Foundation, NATS a project of the Cloud Native Computing Foundation (CNCF). HAProxy is a trademark of HAProxy Technologies, k6 a project of Grafana Labs, Go a project of Google. The book is not affiliated with these organizations and projects and is neither reviewed nor endorsed by them.

The passwords in the book (lab-kurz-123 and relatives) are for the lab only. In production, credentials belong in a password vault, never in a book, a unit file or a shell history.

Enjoy the drill book.

Contents

More