Alex Xu · System Design Interview · built from scratch

The Machine
Room

Five chapters, five working machines — Go and Rust, no pseudocode, no diagrams pretending to be code. This page is the showroom, and every machine below is live. Mash the buttons. Break them. They'll tell you exactly what they're doing.

5 built · 21 queuedGo · Rustbenchmarks or it didn't happen
↓  SCROLL. START MASHING.
CH 1.4

Rate Limiter

rate-limiter-go · Go + Redis

Three algorithms, one honest question: how hard can you hit it before it says no? Set the budget, then hammer the button. Watch the bucket drain, the window slam shut, the log age out.

Allowed 200
0
Blocked 429
0
X-RateLimit-Remaining
5
Retry-After
Implemented in the repoWhat it costs you
Lua-atomic Redis counterskills the INCR/EXPIRE race — one round trip, no lost writes
Fail-open on Redis outagelimiter down ≠ service down; requests pass, metrics scream
Per-key limitingIP · API key · user ID, same interface
net/http + Gin middlewarePrometheus counters wired in behind both
CH 1.5

Consistent Hashing

consistent-hashing-go · consistent-hash-rs

240 keys live on this ring. Kill a node and watch what moves — then look at what plain hash % N would have moved instead. That gap is the entire chapter.

Nodes
4
Keys moved
hash % N would move
Worst node load

Ring positions from CRC-style 32-bit hashing · owner = first virtual node clockwise · O(log n) binary search on a sorted ring · sync.RWMutex in Go, RwLock in Rust for read-heavy traffic.

CH 1.7

Unique ID Generator

uid-generator-go · uid-generator-rs

64 bits, no coordination, no database round trip. Hold the button down and watch the sequence counter climb inside a single millisecond — that's the only thing standing between you and a collision.

↑ hold it down
BIT LAYOUT — live
Generated
0
Collisions
0
Peak seq / ms
0
Throughput

Machine ID derived from the MAC address at boot · custom epoch · clock-skew guard refuses to move backwards · sequence overflow spins to the next millisecond rather than repeating.

CH 1.8

URL Shortener

url-shortener-go · Postgres shards + Redis

Paste anything long. Watch it get Base-62'd down to seven characters, hashed onto a shard by the ring from Chapter 5, then resolve it twice — once cold from Postgres, once warm from Redis.

THE SQUEEZE
ShortShardClicksLast lookup
Nothing shortened yet — squeeze something.

Base-62 over an auto-increment id · consistent-hash sharding across 4 Postgres shards (yes, the Ch. 5 ring) · read-through Redis cache · click analytics with GeoIP · expiry + a token-bucket limiter on writes.

CH 1.13

Search Autocomplete

autocomplete-rs · Rust → wasm

50,000 real English words, weighted by real Google web-corpus counts — not a fixture, not a random string generator. The radix trie answers exact prefixes in microseconds. Then misspell one on purpose and watch what forgiveness costs.

↑ then break the spelling
TOP 10 BY FREQUENCY — exact prefix
Query time
Terms
Trie nodes
Edge labels

 

Radix trie over bytes · every node caches max_subtree_freq, so top-K skips any subtree that cannot beat the heap cutoff · one Levenshtein DP row carried down the walk, abandoned the moment its minimum exceeds the budget. Plain Levenshtein, not Damerau — so a transposition like recievereceive costs two edits, and at a budget of one the trie hands you relieve instead.

Query path only. The RocksDB write-behind and the multi-tenant engine need a server and are not demoed here — see the chapter repo.