Six chapters, six working machines in Go and Rust. Every machine below is live: four run the real libraries compiled to WebAssembly in your tab, two talk to deployed services. Push them until they break.
Three algorithms, one 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.
| Implemented in the repo | What it costs you |
|---|---|
| Lua-atomic Redis counters | kills the INCR/EXPIRE race — one round trip, no lost writes |
| In-memory fallback on Redis outage | Redis down ≠ service down; limiting continues per instance |
| Per-key limiting | IP · API key · user ID, same interface |
| net/http + Gin middleware | Prometheus counters wired in behind both |
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 what the chapter is about.
Ring positions from CRC-32 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.
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.
Machine ID from env var, hostname or IP hash · custom epoch · clock-skew guard refuses to move backwards · sequence overflow spins to the next millisecond rather than repeating.
Paste anything long. It comes back as a random six-character Base-62 code, stored on a Postgres shard picked by the ring from Chapter 5. Then resolve it and see the round trip.
| Short | Shard | Clicks | Last lookup | |
|---|---|---|---|---|
| Nothing shortened yet — squeeze something. | ||||
6 chars from crypto/rand over 0-9A-Za-z · consistent-hash sharding across Postgres shards (the Ch. 5 ring) · read-through Redis cache · click analytics with GeoIP · expiry + a token-bucket limiter on writes.
50,000 English words, weighted by real Google web-corpus counts. The radix trie answers exact prefixes in microseconds. Then misspell one on purpose and watch what forgiveness costs.
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 once its minimum exceeds the budget. Plain Levenshtein, not Damerau — so a transposition like recieve → receive 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.
Pick a name, then click. Every click is a point, and everyone is ranked by how many they've racked up — today, this week, all time. Your rank is pushed to you over a WebSocket, not polled, and every rank is one ZREVRANK: O(log n), at twenty players or a million.
| Rank | Player | Clicks |
|---|---|---|
| waiting for the first snapshot… | ||
One Lua script writes all six boards a click lands on — daily, weekly, all-time × global, regional — atomically · midnight resets by key name + EXPIREAT, no cron · ties go to whoever got there first, packed into the float64 score · Postgres event log is the truth, Redis is rebuilt from it · pushes coalesce per board every 100 ms · writes rate-limited by the Ch. 4 limiter.
Clicks are counted in your tab and sent as one write every 1.5 s — the Ch. 4 limiter allows 60 writes a minute, and a click per request would trip it within seconds. Friends-only boards exist in the API but are not exposed here.