Skip to content
System Designer

Hard · Finance and payments

Stock order matching

Brokers and traders send buy and sell orders, and you pair them fairly: the earliest order at the best price goes first. At the market open a rush of orders arrives in seconds. Every accepted order must be in one agreed sequence, and no trade may be lost or invented. Practise this hard system design problem for free with a Google or GitHub account.

The brief

Brokers and traders send buy and sell orders, and you pair them fairly: the earliest order at the best price goes first. At the market open a rush of orders arrives in seconds. Every accepted order must be in one agreed sequence, and no trade may be lost or invented.

Think of an exchange like Nasdaq.

Users, scale and requirements

Who uses it
300,000 active traders and 300 broker systems
Audience in plain numbers
300,000 users or devices
Normal peak
≈ 10,000 requests per second
Request mix
Write: 45%; Read: 50%; Sign-in: 5%
Speed for 99 of 100 requests
Write: ≈ 250 ms; Read: ≈ 400 ms; Sign-in: ≈ 1,000 ms
Successful requests
99.95%
Data safety
No acknowledged write may be lost.
Monthly budget
≈ $35,000
Data at rest
≈ 6 TB
Where users are
North America: 100%
Home region
North America
Waiting deadlines
Write: 3,600 seconds; Read: 900 seconds; Sign-in: 900 seconds
Fresh reads
People must see their own changes. At most 0.1% of reads may be stale in the model.
Personal reads
50% of reads are private; a shared public copy cannot answer them.
Required proofs
Audit trail; Signed-in access; Tested backups

≈ marks an approximation, just as in the game. Waiting deadlines measure the age of queued work and are separate from interactive response time.

  • Orders and cancels are both writes.
  • Trading hours are 09:00 to 16:00.

Questions that shape the design

Who decides the order of two orders sent at the same instant?

One sequencer. Everything downstream follows its log, and that log is the truth.

Can we lose an order we already acknowledged?

Never. The acknowledgement means the order is safely in the sequence.

What if the network splits in two?

It is better to stop trading on the smaller side than to let two sides disagree about trades.

How are quotes served?

Quotes are copies. A quote a few seconds old is fine for a portfolio screen, not for matching.

The traffic day

Traffic concentrated around market hours. The clock covers 00:00 to 24:00 in the home region. Events add pressure on top of that normal traffic.

  1. 09:30 · Flash crowd

    A scheduled launch brings a sudden rush of requests.

    Traffic for Write, Read, Sign-in reaches 3 times the scheduled load; rises over 60 seconds, holds for 900 seconds and eases over 900 seconds. Other request types keep their scheduled load.

  2. 11:00 · Zone outage

    An availability zone loses power or network access.

    Duration: ≈ 3,600 seconds.

  3. 13:30 · Network partition

    Your regions cannot talk to each other during the partition.

    Duration: ≈ 300 seconds.

What a strong design has to handle

  • Two machines cannot both decide who was first. What single thing can hold the agreed order?
  • Preserve price-time priority through leader failure and order retries.
  • An ordered log gives one agreed sequence and an audit trail for free. The cost is that one partition handles one stream of orders at a time, so orders are split by instrument, not shuffled.
  • Acknowledging at the log means the sender hears "accepted" before the trade is matched. That is how real exchanges work: accepted is not the same as filled.

Make a prediction, run a full traffic day, then compare the result. The in-game editorial opens after a finished day and includes measured reference designs.

Concepts to practise

Related problems