Hands-On Builds — Fifteen Lego-Block Pages
One page per project. Each builds the project's machinery out of numbered, independently runnable blocks — a block is a lego piece that constructs one mechanism, proves it works on its own, and hands what it made to the next one — and then an assembly that wires every block into a single working system and measures it.
These are not summaries of the project pages. They are the executable core of each project, small enough to run in seconds and complete enough that the assembly does something real: a transformer that trains to 0.11 nats, a Raft cluster that elects exactly one leader under partition, a recommender that measures why three of its four models lose to a bincount, an autodiff engine that matches PyTorch to 5.6e-17 over 300 optimisation steps.
Every number on every page was produced by running the code. The pages are
generated by handson/build_pages.py, which slices the code
out of each script and captures that script's real output. Nothing is
transcribed by hand, so a result that drifts cannot silently stay stale on the
page — regenerating rewrites it.
Where a measurement contradicted what I expected, the contradiction stayed in. Six of these pages document a wrong prediction and the experiment that corrected it, because that sequence is the thing the track is actually teaching.
Each page also carries a deep-dive section written for someone who already knows the mechanism: the design space with alternatives, the latency and memory-hierarchy arithmetic that constrains it, what changes on GPU/TPU/SSD/HDD, the advanced algorithms the toy version stands in for, how the project connects to the other fourteen, the failure modes at scale, and the primary sources. The Concept Map collects the eight mechanisms that recur across all fifteen projects and shows where each one appears.
Contents
| Page | What it builds | Blocks | Script | Project |
|---|---|---|---|---|
| P01 — Transformer | Attention from a dot product, then a language model that trains. | 9 | h01_transformer.py (330 lines) | spec |
| P02 — Approximate nearest neighbours | Why a random graph fails, why a navigable one works, and what recall costs. | 7 | h02_ann.py (169 lines) | spec |
| P03 — Vector database | An index is not a database: filtering, persistence, and a planner that chooses. | 6 | h03_vectordb.py (200 lines) | spec |
| P04 — LSM storage engine | Durability first, then the Bloom filter that makes reads survivable. | 7 | h04_lsm.py (220 lines) | spec |
| P05 — Distributed key-value store | Leader election and log replication under loss, duplication and partition. | 7 | h05_distkv.py (239 lines) | spec |
| P06 — MapReduce framework | Why a restricted programming model is what makes fault tolerance possible. | 6 | h06_mapreduce.py (180 lines) | spec |
| P07 — Stream processing | Event time, watermarks, and the accuracy/latency dial made explicit. | 7 | h07_streaming.py (222 lines) | spec |
| P08 — Recommender system | Three of four models lose to popularity. This page is about why. | 8 | h08_recsys.py (277 lines) | spec |
| P09 — Recsys simulator | Feedback loops, position bias, and a bandit that loses for a findable reason. | 7 | h09_simulator.py (270 lines) | spec |
| P10 — A/B testing platform | Peeking, SRM, CUPED, and the type-M error that inflates every underpowered win. | 8 | h10_abtest.py (300 lines) | spec |
| P11 — Programming language | A lexer, a Pratt parser, two backends, and a textbook optimisation that loses. | 8 | h11_language.py (525 lines) | spec |
| P12 — Operating system kernel | Frames, page tables, Bélády's anomaly, scheduling, and a race you can watch. | 8 | h12_kernel.py (339 lines) | spec |
| P13 — Tensor framework | Reverse-mode autodiff that matches PyTorch to 5.6e-17 over 300 steps. | 8 | h13_tensor.py (383 lines) | spec |
| P14 — Hardware-aware ML | Two measured numbers predict a workload, and two modelling bugs get caught. | 7 | h14_hardware.py (337 lines) | spec |
| P15 — The integrated system | Five earlier projects, imported rather than reimplemented, wired into one service. | 6 | h15_integrated.py (269 lines) | spec |
109 blocks, 4,260 lines of runnable Python, 356 KB of generated pages.
Running them
cd handson
python3 h01_transformer.py # every block, then the assembly
python3 h08_recsys.py --block 5 # one block and its prerequisites
python3 h14_hardware.py --quiet # the assembly only
python3 build_pages.py # regenerate all fifteen pages
python3 build_pages.py h04 # regenerate one
Only numpy is required. Three pages use torch if it is installed, to check
their own results against a reference implementation, and skip that check
cleanly if it is not.
The cross-cutting view
The Concept Map is the companion to these pages. Fifteen projects share far fewer than fifteen mechanisms — an approximate test guarding an exact one, an atomic pointer swap for durability, the memory hierarchy as the cost model, the arithmetic of maxima, two-stage retrieval, restriction as the enabler of recovery, the accuracy/latency dial, and amortising a fixed cost. That page indexes every appearance of each.
Where these sit in the track
Walkthroughs are six 40–60 minute miniatures that each end in one surprising finding. These hands-on pages are longer and structured differently: they cover a whole project's mechanisms rather than one idea, and they are meant to be read alongside the project page while you build the real version.
The reading order that works: skim the project page for scope, run the hands-on script to see the mechanisms move, read the hands-on page for what each one costs, then start the real build with the scaffold. The hands-on version is deliberately the smallest thing that demonstrates the mechanism — the project page's milestone list is what turns it into a system.
The self-corrections
Kept deliberately, with the measurement that forced each one:
| Page | What I predicted | What the measurement said |
|---|---|---|
| P08 | more negatives improves ranking | it made it worse; regularisation was the real variable |
| P08 | word2vec's pop^0.75 sampling would help | 0.42x — it divides out the signal the data is made of |
| P09 | Thompson sampling beats greedy | it loses, because exploring at rank 0 costs 34% of all attention |
| P11 | a bytecode VM beats a tree-walker | 0.85x, until the dispatch chain was reordered by frequency |
| P12 | a page-fault cliff at the working-set size | no cliff — a mixture of reference distributions has no knee |
| P13 | a missing un-broadcast silently shrinks the gradient | += raises; the silent bug is =, which reshapes the parameter |
| P14 | one roofline for the machine | one per dtype; an fp64 ceiling made fp32 kernels look superluminal |
Each page links back to its full project specification, and every project page links forward to its hands-on build.