← Questions
Design a stock trading platform
0
I was asked this
No reports yet. Sign in to say where you were asked it.
Design a stock trading platform. Users place market and limit orders; the platform matches buy and sell orders, updates each user's cash and positions exactly once per trade, and streams prices to users in real time.
Requirements
- Functional: place, modify and cancel market and limit orders; check buying power or holdings before accepting an order; match orders per symbol by price and time priority; settle trades into balances and positions; stream quotes and trades; show order status and history.
- Non-functional: very low latency in matching; strict ordering of orders per symbol; every trade applied to balances exactly once; no loss of accepted orders on failure; peaks at market open and close; a full audit trail.
Clarifying questions
- Do we run our own matching engine, or route orders to exchanges?
- How many symbols, users and orders per second at peak?
- Which order types beyond market and limit (stop, time in force)?
- Are there margin accounts or only cash accounts?
- How fast must price updates reach users?
What a strong answer covers
- An order flow: gateway, risk checks that reserve buying power, a sequencer that gives each order a position in a per-symbol log, and the matching engine.
- The matching engine: an in-memory order book per symbol (price levels with queues), single-threaded per symbol for determinism, partitioned across machines by symbol.
- Durability and recovery by replaying the sequenced log; hot standby engines.
- Settlement: trades as events applied idempotently to a ledger of cash and positions; releasing reservations on cancel or partial fill.
- Market data fan-out to many clients, with throttling and snapshots plus deltas.
- Handling the open and close peaks, audit logs, and reconciliation.
Follow-ups
- The matching engine for a busy symbol crashes mid-trade. How do you recover without losing or duplicating trades?
- Add stop orders that trigger on the last trade price.
- A user submits thousands of orders a second. How do you protect the system?
- Halt trading in one symbol on regulatory request.
Sign in to see the worked answer
The full answer, chapter by chapter, with what interviewers expect at each level. Free with an account: one full answer per company.
What the labs asked this week
A weekly email of what OpenAI, Anthropic and the other top AI labs asked engineers, round by round.
Sign in to see the worked answer
The full answer, chapter by chapter, with what interviewers expect at each level. Free with an account: one full answer per company.
Draw your answer hereBoxes, arrows and notes, saved for you to come back to.Sign in to start drawing


