cld-toys › Toys

Toys

Small Python programs that each teach exactly one mechanism of infrastructure software — a rate limiter, a write-ahead log, an LSM tree. Each builds a working mental model of how the thing works, never a usable reimplementation.


A toy is 100–200 lines of core code you can hold in your head at once. Every toy here comes with a commentary: a study guide that explains the concept from scratch, walks the real source in reading order, derives the demo's result arithmetically, and points at the background reading. Click a card to read one.

Every number on these pages was run, not recalled Demo transcripts, counterfactual experiments, and the arithmetic behind each claim are captured from real runs of the real toy before publishing. Where a commentary says "change this character and the result flips," that variant was actually executed.

Available now

Data stores
wal-kv

A key-value store that survives crashes by writing its log first. Then the discovery that the experiment you'd run to prove it works cannot fail: with fsync switched off entirely, kill -9 still returns all five records. Turning fsync on changes nothing — because the bytes were in the kernel, and the kernel isn't what died.

146 lines · stdlib only · 10 sections · 5 self-check questions

Networking
rate-limiter

Token bucket and sliding window log, tuned to the same average rate, fed one identical trace — and they disagree twice, in opposite directions. The bucket's generosity at t=2.5 turns out to be the exact cause of its stinginess at t=5.0.

52 lines · stdlib only · 10 sections · 5 self-check questions

Coming next

The backlog from BACKLOG.md, grouped as it is there. Each names the mechanism it teaches and the "aha" its demo should produce.

The full list, with the aha each demo should produce, is in BACKLOG.md. A suggested ramp rather than picking randomly: wal-kvlsm-treeconsistent-hashingraft-toytiny-interpretermini-asyncio.