Stock Trading App (Robinhood)

Brokerage orders and live prices

Design a retail brokerage app: millions of people watch live prices and place market and limit orders, which the broker checks against their buying power and routes to exchanges and market makers, then tracks to the last fill.

Overview

A retail brokerage app lets people watch stock prices and buy or sell shares. The broker is not the exchange: it does not match buyers with sellers. It holds customer accounts, checks that a customer can pay, sends each order to an exchange or a market maker (a firm that trades against incoming orders), and records what comes back. A clearing firm then settles the trades and holds the cash and shares; in the US, most stock trades settle one business day after the trade (T+1).

The design splits into two paths with opposite needs. The price path is huge and forgiving: millions of open screens, each watching a few dozen symbols, where a price that is 200 ms old is fine and a skipped tick is invisible. The order path is small and strict: a few thousand orders a second at the opening bell, where a lost order, a duplicate order or an overspent account is a real loss. Keep them apart, so a flood of quotes can never slow an order.

Questions to ask first

  • Are we the broker or the exchange? — The broker; orders go out to exchanges and market makers
  • Which products? — US stocks in a cash account; no options, crypto or margin
  • Which order types? — Market and limit, day orders, place and cancel
  • How fresh must prices be? — Under a second on screen; quotes are informational, never used to fill
  • How many users? — 2 million connected at the open, 5 million orders a day
  • Trading hours? — The regular session only, 9:30 a.m. to 4:00 p.m. Eastern

What you will be able to do

  • Fan live prices out to millions of clients with per-symbol subscriptions and conflation.
  • Make order entry safe to retry with a client order ID, end to end.
  • Check and hold buying power before an order leaves the broker, and release it correctly.
  • Drive each order's state from FIX execution reports, including partial fills and cancel races.
  • Reconcile with the clearing firm and plan for the opening bell.

Key concepts

  • Quote fan-out
  • Per-symbol subscriptions
  • Conflation
  • Client order ID
  • Buying-power hold
  • FIX execution reports
  • Order state machine
  • Positions read model
  • Clearing reconciliation
  • Opening-bell spike

Functional requirements

  • See live prices for a watchlist and a stock page
  • Place a market or limit order to buy or sell
  • Cancel an open order
  • See each order's status, fills and average price
  • See positions, cash, buying power and portfolio value

Non-functional requirements

  • An order is never lost and never placed twice, even when the client retries
  • No order can spend more than the account's buying power
  • Prices reach the screen within about 1 second of the feed (a target we chose)
  • Order acknowledgment in under 500 ms at p99, not counting the venue (a target we chose)
  • The order path stays up through the opening-bell spike; prices may degrade first
  • Every order and execution kept for the required retention period, unchangeable

Interview questions

  • How do you push live prices to millions of clients?
  • How do you make sure an order is never placed twice?
  • How do you stop a customer from spending money they do not have?
  • What happens when a user cancels an order that is filling?
  • How does the broker know what actually traded?
  • How do you handle the opening bell?
  • What does reconciliation with the clearing firm catch?
  • How is this different from designing the exchange?

Sign up free to read the full topic

More System Design topics

Start free on Cariara · Coding problems · System design studio