See It Flow

Design a Stock Exchange — Visual Design Journey

Watch a single order gateway evolve, bottleneck by bottleneck, into a sequenced, durable, fenced-failover matching engine that fills orders by strict price-time priority.

15 scenes · 39 narrated steps · interactive, self-paced

Design a Stock Exchange

Design a Stock Exchange
A long-form engineering design session — watch order matching, sequencing and durability evolve, bottleneck by bottleneck.
Maximize to view synchronized narration and navigate between explanation steps.

What You Should Understand Now

  • Price-time priority is deterministic: when two resting orders share a price (S1 and S2 both at $101.00), the one with the earlier sequence number is always filled first — fairness comes from sequencing, not from which request "arrives" fastest over the network.
  • An accepted order is never the same thing as an executed trade — a limit buy below the best ask simply rests on the book, and a limit price is a ceiling on what you will pay, never a promise of what you will pay, as the multi-level sweep in Test B demonstrates.
  • IOC and FOK orders answer the same question — "what if the book can't fill me completely?" — in opposite ways: IOC takes the partial fill and cancels the rest, while FOK requires the entire order to be fillable right now or it executes nothing at all.
  • A cancel request racing a matching order is resolved by whichever the sequencer serialized first — a completed fill can never be retroactively undone by a cancel that is sequenced after it.
  • A single-writer matching engine per instrument is what makes price-time priority provably correct without locks, but durability requires a journal committed before acknowledgment, and failover requires epoch fencing so two engines never believe they own the same book at once.
  • Market data is a broadcast of the truth, not the truth itself: it has its own sequence numbers, a subscriber detects gaps and resynchronizes from a snapshot, and none of this is allowed to sit on the matching engine's hot path.

Concepts in This Visual

Price-Time PriorityOrder Book (Bid / Ask / Spread)Limit, Market, IOC & FOK OrdersCancel/Fill Race SerializationPre-Trade Risk GateDeterministic SequencerSingle-Writer Matching EngineDurable Journal + Snapshot ReplayEpoch Fencing & Standby PromotionMarket Data Snapshot + DeltaPartitioning by InstrumentTrading HaltsPost-Trade Clearing Handoff

Go Deeper