Exercise · Financial & Trading
Stock Exchange — Matching Engine
Whiteboard exercise. Try the problem cold, then reveal the rubric to self-score.
Out of 10 points45 min whiteboardReference solution →
01
Prompt
Design a stock exchange. Price-time priority order matching, 100K trades/sec/symbol peak, < 1ms p99 latency, strong consistency.
Time budget: 45 min whiteboard. Draw architecture, estimate numbers, discuss tradeoffs.
02
Hints (progressive — click to reveal)
Hint 1
In-memory matching per symbol. One process per symbol. Serialized with a journal.
Hint 2
Pre-trade risk holds funds before matching. Trade settler writes double-entry ledger post-fill.
Hint 3
Single-threaded matching > parallel. Determinism + replayable state > throughput.
03
Rubric — 10 points
- +2 Per-symbol single-threaded matching engine with in-memory order book (price-time priority)
- +2 Every mutation journaled (append-only log) before apply; deterministic replay on restart
- +1 Pre-trade risk: balance-hold on order submit; rejected if insufficient
- +1 Trade settler writes double-entry ledger (buyer/seller funds + instrument); idempotent by trade_id
- +1 Market-data fanout via WS/multicast to subscribers; delta updates; < 10ms latency target
- +1 Hot vs cold order book: hot levels around mid-price; deep tail rarely touched
- +1 Circuit breakers on extreme price moves; halt symbol on anomaly
- +1 Clock-drift + jitter: deterministic sequence numbers from matching engine; not wall-clock
Self-score: tally the points you would have mentioned unprompted. 7+ is interview-ready on this problem.
04
Red flags (things that tank the interview)
- Matching in a DB transaction (too slow for 100K/sec)
- Parallel matching across symbols with no serialization (order crossings)
- No journaling / replay (state lost on crash)
- Single-machine matching for entire exchange (no per-symbol isolation)
- Skipping pre-trade risk (allows negative-balance order)