Design a stock exchange order matching engine
PremiumLow-level designHard
- Order book
- Price time priority
- Matching engine
Quick answer
This low-level design interview question asks you to design a stock exchange order matching engine. Aim for a design that is modelled as clear classes, interfaces and relationships that can handle new requirements without a rewrite. Interviewers want to see how you name responsibilities, keep classes small and reason about change.
The problem
Stock exchange order matching engine, low level design: build the limit order book and matcher for one symbol. Traders send limit and market orders; the engine matches them by price-time priority and emits trades. The hard parts are fast cancels, partial fills and 1 million messages per second, deterministically.
A limit order states a price and a quantity; a market order states only a quantity. The engine keeps an order book of resting orders, matches incoming orders against the best opposite prices, and emits trade events and book updates. Traders can cancel or modify resting orders.
What must a stock exchange order matching engine do?
- Order types: Limit (price, quantity), market (quantity), with time-in-force of day, immediate-or-cancel (IOC) and fill-or-kill (FOK).
- Matching rule: Price-time priority. A buy matches the lowest asks first; among equal prices, the earliest order first. A trade executes at the resting order's price.
How well must it do it?
- Throughput and latency: 1 million order messages per second for the symbol with a median match latency under 10 µs.
- Deterministic: Replaying the same input sequence must produce the same trades and sequence numbers.
What scale should you design for?
Use these numbers in your estimates.
The scale numbers unlock with this questionUnlock
Key concepts
- Order book
- Price time priority
- Matching engine
- Single writer
- Event sourcing
- Low latency
How you’ll practise
- Requirements
- Core objects
- Class relationships
- Key flows
- Extensibility
- Wrap-up
Lala, personalized to you, gives a hint when you ask and reviews your design when you are ready.
What do interviewers look for?
In any low-level design round.
- Lists the use cases before writing classes
- Gives each class one clear responsibility
- Uses interfaces where behaviour is likely to change
- Applies a design pattern only when it solves a real problem
- Handles edge cases and invalid states explicitly
- Walks through one use case end to end with the model
Questions people ask about this interview question
- Which design type is this question?
- It is a low-level design question. You design a stock exchange order matching engine and explain your choices the way you would in an interview.
- Is this question asked at entry level?
- It is marked Hard. It suits engineers preparing for senior interviews, where you are expected to drive the discussion and go deep on trade-offs.
- What should I cover first?
- Start with the use cases and the core entities, then the responsibilities of each one. Agree on scope with the interviewer before you design anything.
- Can I practise it for free?
- It is a premium question. Sign up and unlock it once for 10 credits; it then stays unlocked. When you finish, Lala, your personalized AI mentor, can review your design for 30 credits.
Related questions
Updated · Written by the SevyDevy team