algomiBlogs
← All posts

Stock Exchange and Broker Design: Order Books, Matching Engines, and Risk

Algomi Research · Created 2026-09-29 · Updated 2026-10-15 · System Design

Interview Roadmap Deep Dives · Part 13 of 28
Collaborative Editing: Operational Transformation, CRDTs, and PresenceChat and Notification Systems: Real-Time Delivery at Scale
Page 1 of 1

Neha's first trade, and a mango auction

Neha opens a broker app and places her first order: buy 100 shares of MANGO at ₹99.60. Two seconds later the app says Filled. This guide follows that one order, and a few that go wrong, from her phone through the broker and into the exchange. (Neha, the broker, the MANGO share and every number here are made up for teaching.)

To understand the exchange, picture the mango auction hall in Ratnagiri:

  • Sellers shout the lowest price they'll accept, and buyers shout the highest they'll pay.
  • Whenever a buyer's price meets a seller's, a deal is struck at once.
  • Among people shouting the same price, the one who shouted first goes first.
  • Everyone must see the same fair order of events, and the auctioneer must never lose a shout.

A stock exchange is that hall with three unusual demands:

  • Correctness: money and legal fairness.
  • Determinism: replaying the same inputs must give the same trades.
  • Speed: microseconds to milliseconds.

A broker sits between people like Neha and the exchange. The story covers both sides:

What happens Idea it forces
"Who gets my order first?" The limit order book and price-time priority
"How can one engine be fast and fair?" The single-threaded, sequenced matching engine
"The engine crashed at 10:15" Journal, replay and hot standby
"Where did my order go after I tapped Buy?" The trade lifecycle
"Neha typed 10,000 instead of 100" Pre-trade risk checks
"The same ₹10,000 bought shares twice" Reserve-then-debit and the ledger
"Budget day: a million people watching prices" Market data fan-out

This guide links to Payment system for money movement and Consensus for replication.

1. "Who gets my order first?": the limit order book

An order is an instruction with a side (buy or sell), a quantity and a price type. A limit order names a price, and a market order takes the best available price.

The order book for one instrument keeps resting (not yet filled) limit orders in two sorted sides. It is the auctioneer's two lists of shouts.

You've reached the free preview of this post.

Subscribe to the Blogs plan (₹99/mo) — or use any Algomi Suite, Career, Investor, or Trader plan — to keep reading.

See plans

Sources

Interview Roadmap Deep Dives · Part 13 of 28
Collaborative Editing: Operational Transformation, CRDTs, and PresenceChat and Notification Systems: Real-Time Delivery at Scale