Low-Latency Order Book · Handbook
0/0 gates

Building a Low-Latency
Order Book from Scratch

One beginner's exploration of C++, systems programming,
and how high-frequency trading infrastructure actually works
A learning journal, not a textbook — written while building the thing
to sharpen C++ and understand a domain I'd never touched
Why this exists (read me first) I'm not a quant and I'd never written low-latency C++ before this. I built the order book to learn — and wrote this booklet to make the learning defensible, so I could explain every decision out loud rather than wave at code I half-understood. It's deliberately thorough: I'd rather over-explain than fake fluency. Treat it as "here's what I explored and why," not "here's the one true way." Where I made a beginner's simplification, I say so.

How to use this

One file — no account, no server, nothing to install. Open it from disk on any machine you own. Tick boxes save into whichever browser you tick them in. The ladder tells you what to build next; the chapters explain why it works; each rung links straight to the chapters it needs.

0 of 0 gates passed

Don't read this handbook

Reading produces recognition, not retrieval — which is exactly why most of those 109 LeetCode hards aren't there when you reach for them. A better-written document would fail the same way. So each rung is locked into a four-step loop, and the explanation genuinely will not open until you have committed to an answer:

1 · GuessAnswer the rung's questions in writing, with the chapters shut. Badly is fine. Badly is the point.
2 · ReadOnly now do the chapters unlock — and you find out which answers were wrong. That correction is the learning.
3 · BuildThe gates decide whether you understood it or merely recognised it. You'll remember invalidation rules from the crash, not the chapter.
4 · Say itTwo minutes out loud, laptop shut, then write the decision entry from memory. This is the part that shows up in the room.

You do not need to internalise 22 chapters. You need what you use — six for rung 1, two for rung 2, none for rung 3. A chapter no rung names is reference, not curriculum. Never read this front to back; raid it. And keep the ratio near one part reading to four parts typing, because the typing is the part that sticks.

When a line feels like three hours of research

It is almost never three hours, and it is almost always one of three gaps. Name which one and an intimidating paragraph becomes four or five specific questions, most of which resolve in minutes:

An unexplained identity“the slot is counter & (Capacity-1)”. One fact: for powers of two, AND with n-1 is modulo n. Twenty minutes with a calculator, permanently.
An unstated motivation“you cannot use a mutex”. Ask why not. Here: a contended lock parks the thread in the kernel, and waking costs microseconds against a budget of nanoseconds.
An unnamed invariant“size is tail - head”. Why is that true? Because both counters only ever increase — which also makes full and empty distinguishable.

Ten of these chapters were originally a title and a diagram, with no prose at all — Ch 5 had twenty-one words. Those have been written out properly, so if a chapter still reads as a summary rather than an explanation, that is the chapter's problem and not yours. Say so and it gets fixed.

Twenty-five to thirty-two evenings

Roughly five to six weeks at most evenings. Rungs 1–3 are ten to twelve of them — comfortable before 5 October even while working, and they are the rungs where a second opinion is worth most. Rungs 4–7 grade themselves: a replay either reproduces the state hash or it doesn't, the reference model names the diverging sequence, the benchmark either got faster or it didn't. That is the half built to be done alone. If the window compresses, cut scope inside rung 6 by shipping fewer optimisations — never by skipping rung 5.

Save as PDF

Press Ctrl+P → Destination: "Save as PDF" → Margins: "Minimum"