Stock Exchange

Design the core trading system of a stock exchange: accept orders into a central limit order book, match at price-time priority, and when your own book cannot complete an order, finish the job across...

00

Practice checkpoints

The requirements are open as a taste. From the numbers onward, the full guide opens in the app.

  1. 01
    Clarify scope
  2. 02
    Requirements + scale
  3. 03
    API + data modelUnlocks in the app
  4. 04
    Draw architectureUnlocks in the app
  5. 05
    Deep diveUnlocks in the app
  6. 06
    Trade-off decisionUnlocks in the app
01

Requirements that shape the design

Do not only state requirements. Ask for them. Each card pairs the design constraint with a clarification question you can say out loud before drawing the architecture.

Functional requirements

01Which order types must the book support?

All four core types, each defined by how it completes: a market order consumes the book immediately at whatever prices rest there; a limit order rests at its price until filled or cancelled; IOC (immediate-or-cancel) takes what is available and cancels the rest; cancel/replace re-prices without losing queue position unfairly.

02An order arrives — where does it try to fill first?

Own book first: the order matches against resting orders at price-time priority — best price wins, first-come wins ties — in microseconds, and only the unfilled residual ever leaves the building.

03The book fills 4,000 of 10,000 — how does the rest get done?

The residual is completed across the street: internalize against a wholesaler’s streamed quote when it improves on the public best price, otherwise route a child order to the venue displaying the best protected quote — never execute through a better price shown elsewhere.

04Fills now come back from three places — what does the client see?

One parent order, many fill sources: every fill — local book, wholesaler, away venue — appends to the parent; state (partially_filled 7,000/10,000) is derived from the fill log, and the order is done only when the residual is zero or explicitly cancelled.

05A cancel arrives while 3,000 shares are in flight to another venue?

Cancel is routed like an order: the resting slice cancels instantly, the in-flight routed slice sends a cancel to its venue, and the final state waits for that venue’s answer — shares that filled before the cancel landed stay filled.

06How do watchers learn the book moved?

Every match publishes: trade prints and book deltas flow to a separate market-data plane, tiered per subscriber (conflated top-of-book for most, full depth for professionals), and the matching path never waits for a subscriber.

Out of scopeCustomer cash, buying power, and the account ledger (the retail brokerage sibling question) · Clearing and settlement after the trade is done · Listing requirements, market surveillance, and halt logic — the audit trail feeds them, the design does not include them

Non-functional requirements

01The engine host dies at 10:14 — what does the replacement know?

Deterministic: the same input sequence always produces the same book — matching is one thread per symbol reading a sequenced input log, so failover is replay, not reconstruction guesswork.

02What latency does each stage of the fill owe?

Microseconds to match, about a millisecond to ack: the local fill path never waits on routing, journaling to disk happens before the ack, and only the residual pays the multi-millisecond street latency.

03A venue resends a fill and a member resends an order — what happens?

Never a double fill: outbound child orders carry deterministic child ids the venue dedupes on, and inbound execution reports dedupe on (venue, execution id) — correctness beats availability on the order path.

04The regulator asks what happened at 9:31:02 — what do you produce?

The sequenced event log IS the exchange: every accept, match, route, fill, and cancel is journaled in order and replayable — the regulator’s question ‘what happened at 9:31:02’ has one answer.

05How do you prove no participant jumps the queue?

Fair by construction: price-time priority is absolute, nobody observes a match before it is sequenced, and market data leaves on the same feed for everyone — fairness is architecture, not policy.

Keep asking — the interview is a conversation

Real interviews probe far more than a tidy list. These are the scope questions that separate candidates who interrogate the problem from those who recite it.

  • Are we a protected exchange under trade-through rules, or an ATS with more routing freedom — and does the answer change per symbol?
  • Is the flow retail or institutional — does payment-for-order-flow exist here, and does it change what ‘best execution’ must prove?
  • Which order types are in scope day one — market, limit, IOC — and do odd lots and fractional shares follow the same rules?
  • How long may a residual wait at an away venue before we re-route it, and who owns that timeout?
  • Does any subscriber tier truly need every book delta, or is conflated top-of-book acceptable for all but a professional tier?
01

Unlock the full playbook for Stock Exchange

Numbers, architecture diagram, API and data model, deep dives, expected topics, self-check, whiteboard starter, and common mistakes unlock inside the app.

02

Numbers that force architecture decisions

Locked in the app

03

Architecture path

Locked in the app

04

API and data model

Locked in the app

05

Deep dive directions

Locked in the app

+Series

Practice the related series