techdiagrams.net
← All templates

Trading venue order book

A deterministic matching engine behind a lock-free ring buffer and a sequencer — event-sourced so that replaying the journal rebuilds the exact book, tick for tick.

Open in editor — free, no login Download JSON
new order / canceldrainseq #184,224,001…append eventsreplaypublishfanoutTrading ClientsFIX / binary gatewaysOrder Gatewayvalidate · rate-capRing Bufferlock-free · boundedSequencerstamps total orderMatching Enginesingle-threaded state machineEvent Journalappend-onlyWarm Replicareplays → identical bookMarket Datatrades · quotes · depthSubscribersmarket data feedswhy single-threaded wins here: the engine does no I/Oand holds no locks — it just folds ordered events.Determinism turns disaster recovery into `replay`.

What this design does

Exchanges cannot say 'roughly what happened'. This design gets determinism from three decisions: all order flow funnels through a single sequencer that stamps a total order, the matching engine is a single-threaded state machine (no locks to reason about, nothing to race), and every state change is an event in an append-only journal. Recovery is not a special case — a warm replica replaying the same journal arrives at the same book, always.

The patterns it composes

Import it, attach your own numbers, and verify the design against failures — or read the engineering notes.