Phase 1 — Clarify & Scope
Interviewer: Design a stock exchange — think NYSE or NASDAQ. What do you want to clarify?
Candidate: This is a complex domain. Key questions:
- What types of orders — market orders, limit orders, stop orders?
- What's the matching engine model — price-time priority (FIFO)?
- What's the throughput requirement — orders per second?
- Is this equities only, or also options, futures, crypto?
- Latency SLA — HFT firms need microseconds; retail traders need milliseconds?
Interviewer: Equities only. Limit orders and market orders. Price-time priority matching. 100,000 orders/sec peak. Latency: order acknowledgment < 1 ms, trade execution notification < 10 ms. No HFT co-location for now.
Candidate: Let me size this:
\text{Trade notifications} \approx 100{,}000 \times 0.3 = 30{,}000 \text{ trades/sec (30% match rate)}
Interviewer: What are the core requirements?
Candidate:
- Accept limit orders (buy/sell at price ≤/≥ limit) and market orders (execute at best available)
- Maintain an order book per symbol: sorted bid/ask price levels
- Match orders in price-time priority: best price first, oldest order at same price first
- Emit trade execution notifications and order status updates
- Market data feed: real-time order book state and last trade prices
Non-functional:
- Order acknowledgment: < 1 ms (order received and validated)
- Matching…
In the full tutorial
- Phase 2 — High-Level Architecture
- Phase 3 — Deep Dive & Evolution
- Phase 4 — Robustness & Operations