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

PageWhat it buildsBlocksScriptProject
P01 — TransformerAttention from a dot product, then a language model that trains.9h01_transformer.py (330 lines)spec
P02 — Approximate nearest neighboursWhy a random graph fails, why a navigable one works, and what recall costs.7h02_ann.py (169 lines)spec
P03 — Vector databaseAn index is not a database: filtering, persistence, and a planner that chooses.6h03_vectordb.py (200 lines)spec
P04 — LSM storage engineDurability first, then the Bloom filter that makes reads survivable.7h04_lsm.py (220 lines)spec
P05 — Distributed key-value storeLeader election and log replication under loss, duplication and partition.7h05_distkv.py (239 lines)spec
P06 — MapReduce frameworkWhy a restricted programming model is what makes fault tolerance possible.6h06_mapreduce.py (180 lines)spec
P07 — Stream processingEvent time, watermarks, and the accuracy/latency dial made explicit.7h07_streaming.py (222 lines)spec
P08 — Recommender systemThree of four models lose to popularity. This page is about why.8h08_recsys.py (277 lines)spec
P09 — Recsys simulatorFeedback loops, position bias, and a bandit that loses for a findable reason.7h09_simulator.py (270 lines)spec
P10 — A/B testing platformPeeking, SRM, CUPED, and the type-M error that inflates every underpowered win.8h10_abtest.py (300 lines)spec
P11 — Programming languageA lexer, a Pratt parser, two backends, and a textbook optimisation that loses.8h11_language.py (525 lines)spec
P12 — Operating system kernelFrames, page tables, Bélády's anomaly, scheduling, and a race you can watch.8h12_kernel.py (339 lines)spec
P13 — Tensor frameworkReverse-mode autodiff that matches PyTorch to 5.6e-17 over 300 steps.8h13_tensor.py (383 lines)spec
P14 — Hardware-aware MLTwo measured numbers predict a workload, and two modelling bugs get caught.7h14_hardware.py (337 lines)spec
P15 — The integrated systemFive earlier projects, imported rather than reimplemented, wired into one service.6h15_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:

PageWhat I predictedWhat the measurement said
P08more negatives improves rankingit made it worse; regularisation was the real variable
P08word2vec's pop^0.75 sampling would help0.42x — it divides out the signal the data is made of
P09Thompson sampling beats greedyit loses, because exploring at rank 0 costs 34% of all attention
P11a bytecode VM beats a tree-walker0.85x, until the dispatch chain was reordered by frequency
P12a page-fault cliff at the working-set sizeno cliff — a mixture of reference distributions has no knee
P13a missing un-broadcast silently shrinks the gradient+= raises; the silent bug is =, which reshapes the parameter
P14one roofline for the machineone 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.