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.
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
- Ring buffer (Disruptor) — lock-free ingestion decouples bursty gateways from the engine
- Singular update queue — one sequencer stamps a total order — the arbiter of 'who was first'
- Event sourcing — the journal of events is the book; state is derived
- Deterministic replay — same journal + same code = same book; recovery is replay
- Market-data fanout — trades and quotes broadcast without touching the hot path
Import it, attach your own numbers, and verify the design against failures — or read the engineering notes.