ProblemTransactions and payments
Stock exchange
NewMatch buyers and sellers of 5,000 stocks within a millisecond, fairly, and show every trade to the market.
The brief
Stock exchange · suggested for Senior
Design a stock exchange
Design a stock exchange’s trading system: member firms send orders for about 5,000 listed stocks, the exchange matches buyers with sellers continuously, every firm hears about its orders and fills, and the whole market sees every trade, with nothing accepted lost when a server fails and no member treated better than another.
You run the technology for a national stock exchange. About 2,000 sessions from member firms (brokers, banks and market makers) send orders to buy and sell about 5,000 listed stocks between 9:30 and 16:00. Most messages are cancels and changes from market makers moving their prices, and the open and the close bring bursts ten times the day’s average. The exchange matches orders continuously, tells each firm about its orders and fills, sends every trade and every change to the waiting orders to about 10,000 market-data subscribers, and reports every trade to the clearing house. Each firm has a credit limit agreed with its clearing firm. Design the trading system, from a firm sending an order to everyone hearing about the trade.
Functional requirements
- CoreMember firms send limit and market orders to buy or sell listed stocks, and can cancel an order or change its price or size.
- CoreOrders match continuously during trading hours: the best price first, then the earliest order at that price.
- CoreEach firm hears about every order it sent: accepted, filled in part or in full, cancelled or rejected.
- CoreA public feed carries every trade and every change to the waiting orders, to firms and data vendors.
- CoreEach firm has a credit limit its orders must not exceed, and orders that are clearly mistakes do not trade.
- CoreEvery order and trade is kept for regulators.
Non-functional requirements
- DurabilityAn accepted order or a reported fill is never lost when any one server or rack fails; if the whole data centre is lost, at most a stated few milliseconds may be lost.
- ConsistencyThe same orders always produce the same trades, and priority goes by arrival at the exchange.
- LatencyAn order is answered within 1 ms of reaching the exchange, and trades are published on the public feed within 1 ms, at the 99th percentile.
- AvailabilityTrading resumes within seconds of losing a server.
- QualityNo member gets priority, or market data, ahead of another by how or where it connects.
- QualityOrders and trades are kept for 7 years.
Scale
- ScaleAbout 5,000 listed stocks and about 2,000 member sessions.
- ScaleAbout 1 billion order messages a day, most of them cancels and changes; about 500,000 a second at the open and the close; up to 50,000 a second on the busiest stock.
- ScaleAbout 30 million trades a day, over a 6.5-hour trading day.
- ScaleAbout 10,000 market-data subscribers.
Nice to mention (below the line)
- Below the lineOpening and closing auctions.
- Below the lineTrading halts and circuit breakers.
- Below the lineStop orders and other order types.
Out of scope
- Out of scopeClearing and settlement.
- Out of scopeThe brokers’ own apps.
- Out of scopeOptions, futures and crypto custody.
The variant
One fully specified brief, with the level it suits best. You can practise it at any level.
- Stock exchangeSuggested for Senior
Where member firms trade 5,000 stocks: orders matched in the order they arrived, nothing accepted lost when a server fails, every member treated alike, every trade published within a millisecond.
9 steps · 7 must-pass · about 49 min at Senior
What each level is graded on
Stock exchange, step by step. A result at a level needs its must-pass steps answered, and only the steps you answer count. Going up a level adds steps or holds them to a stricter bar.
| Step | Entry level | Mid-level | Your levelSenior | Staff |
|---|---|---|---|---|
| The numbers that shape the design (optional) | Graded | Graded | Graded | Graded |
| Orders, trades and the book | Graded | Graded | Graded | Graded |
| Sending orders and hearing back | Graded | Must-pass | Must-pass | Must-pass |
| An order, end to end | Must-passcan block | Must-passcan block | Must-passcan block | Must-passcan block |
| Who gets filled first | Must-pass | Must-pass | Must-pass | Must-pass |
| The matcher dies at 10:31 | Must-pass | Must-passcan block | Must-passcan block | Must-passcan block |
| A fat finger, and a firm over its limit | — | Must-pass | Must-pass | Must-pass |
| Ten thousand screens, one feed | — | — | Must-pass | Must-pass |
| Trading on, seconds after losing a server | — | — | Must-pass | Must-pass |
| The opening bell | — | — | — | Must-pass |
| At this level | 6 steps 3 must-pass about 31 min | 7 steps 5 must-pass about 37 min | 9 steps 7 must-pass about 49 min | 10 steps 8 must-pass about 56 min |
Entry level6 steps · 3 must-pass · about 31 min
- The numbers that shape the design (optional)Graded
- Orders, trades and the bookGraded
- Sending orders and hearing backGraded
- An order, end to endMust-passcan block
- Who gets filled firstMust-pass
- The matcher dies at 10:31Must-pass
Mid-level7 steps · 5 must-pass · about 37 min
- The numbers that shape the design (optional)Graded
- Orders, trades and the bookGraded
- Sending orders and hearing backMust-pass
- An order, end to endMust-passcan block
- Who gets filled firstMust-pass
- The matcher dies at 10:31Must-passcan block
- A fat finger, and a firm over its limitMust-pass
SeniorYour level9 steps · 7 must-pass · about 49 min
- The numbers that shape the design (optional)Graded
- Orders, trades and the bookGraded
- Sending orders and hearing backMust-pass
- An order, end to endMust-passcan block
- Who gets filled firstMust-pass
- The matcher dies at 10:31Must-passcan block
- A fat finger, and a firm over its limitMust-pass
- Ten thousand screens, one feedMust-pass
- Trading on, seconds after losing a serverMust-pass
Staff10 steps · 8 must-pass · about 56 min
- The numbers that shape the design (optional)Graded
- Orders, trades and the bookGraded
- Sending orders and hearing backMust-pass
- An order, end to endMust-passcan block
- Who gets filled firstMust-pass
- The matcher dies at 10:31Must-passcan block
- A fat finger, and a firm over its limitMust-pass
- Ten thousand screens, one feedMust-pass
- Trading on, seconds after losing a serverMust-pass
- The opening bellMust-pass
- Must-pass
- a result at that level needs this step answered.
- Can block
- a miss there is a Blocking issue at that level.
Going up a level
- Mid-level
- “Sending orders and hearing back” becomes must-pass.A miss on “The matcher dies at 10:31” can now block the result.Adds “A fat finger, and a firm over its limit”, must-pass.
- Senior
- Adds “Ten thousand screens, one feed”, must-pass.Adds “Trading on, seconds after losing a server”, must-pass.
- Staff
- Adds “The opening bell”, must-pass.
Skills this problem practises
Your coach tracks readiness per skill across every problem you practise. Each links to the lesson that teaches it.
- Capacity estimation
- API design
- Idempotency and retries
- Data modelling
- Sharding and partitioning
- Queues and async messaging
- Consistency and concurrency
- Replication and durability
- Failure modes and recovery
- Observability and operations
- Latency budgets
- Rate limiting and abuse
Worked solution
Try it first: practise a variant, then read the walkthrough and compare it with your own design. Reading it first makes the practice much less useful.
Learn: Design a stock exchangeYour history
Sign in to see your sessions on this problem.