Design a Brokerage Order Processing System
Design an order-processing platform that safely accepts, routes, tracks, and reconciles retail brokerage orders.
Problem statement
For this exercise, assume customers place and cancel market or limit orders for configured spot assets, including cash equities or cryptocurrency, through a pre-funded brokerage application. Amounts and quantities use exact asset units with explicit denominations and instrument-defined precision.
Every accepted order must reserve the required buying power or sellable position before it may be routed to an exchange, and a retry must not create a second logical order. The platform tracks a submitted order through accepted, routed, partially filled, filled, canceled, rejected, or reconciliation-required states.
Exchange acknowledgements and execution events may be duplicated, delayed, or reordered, so customer-visible state and account balances must converge from an auditable lifecycle.
Customers can inspect current status and executions, while operators can reconcile uncertain orders without silently releasing reserved assets. Support 100,000 order commands per second at peak across 10 million accounts, with one hot symbol receiving 10,000 commands per second and up to five million open orders.
Return an authoritative accepted or rejected response within 200 ms at p99 when dependencies are healthy. Exchange event streams may peak at 500,000 events per second and use at-least-once delivery. Retain complete order and execution history for 30 days for replay and compact audit history for one year.
Exclude market-data construction, exchange matching internals, margin lending, options, post-trade clearing, custody, on-chain transfers, and blockchain settlement. Kafka, MySQL, microservices, CDC, and caching are possible implementation choices to justify rather than required technologies.
What to build
- Customers can idempotently place market or limit orders and request cancellation with explicit accepted, rejected, duplicate, or uncertain outcomes.
- The brokerage reserves buying power or sellable position before routing an accepted order and never routes an order without that reservation.
- Exchange acknowledgements, fills, rejects, and cancellations update one authoritative order lifecycle exactly once in effect despite duplicate or reordered delivery.
- Customers can query status and executions, and operators can explain, replay, and reconcile orders whose external outcome is uncertain.
At scalePractice assumption
- Peak load is 100,000 order commands per second across 10 million accounts, with one hot symbol receiving 10,000 commands per second and up to five million open orders.
- Healthy order acceptance or rejection completes within 200 ms at p99, and the service never trades correctness for an optimistic response.
- Exchange lifecycle input peaks at 500,000 events per second and may be duplicated, delayed, or reordered; uncertain orders keep their reservation until reconciliation.
- Complete order and execution events remain replayable for 30 days and compact audit history remains queryable for one year.