System Design: Retail Stock Trading Platform (Robinhood-like)
Context and Assumptions
Design a mobile-first, retail stock trading platform with a clearing broker partner for custody and settlement. U.S. equities settle on T+1. Start with cash accounts (no margin or options at launch), add options/crypto later. Assume 24/5 support for extended hours and a third-party market data vendor for SIP/top-of-book.
Requirements
-
User Onboarding and Funding
-
KYC/AML: identity verification, sanctions screening, fraud checks, account opening with clearing broker.
-
Funding: ACH (Plaid or micro-deposits), wires, with holds and returns handling.
-
Account types: individual cash accounts now; margin/options later.
-
Balances and Buying Power
-
Real-time cash balances: settled vs unsettled, withdrawals, holds.
-
Buying power calculations and guardrails.
-
Market Data
-
Ingest vendor feeds (SIP, top-of-book), maintain symbol master.
-
Stream quotes to clients with throttling and coalescing.
-
Orders
-
Submit/validate market, limit, stop (stop-market, stop-limit) orders.
-
Risk checks: buying power, symbol status (halts), duplicate prevention (idempotency), fat-finger checks.
-
Acknowledge, route to market makers/exchanges, and manage order state.
-
Routing and Post-Trade
-
Route via SOR to market makers/exchanges.
-
Receive executions/drop copies; integrate with clearing broker for confirmation, allocation, and settlement.
-
Portfolio and Positions
-
Positions and lots with cost basis (FIFO default), realized/unrealized PnL.
-
Corporate actions (splits, dividends, symbol changes, mergers) and DRIP.
-
Data Model and Storage
-
Core entities: users, accounts, cash ledger, orders, executions, positions/lots, instruments, ticks, corporate actions.
-
OLTP for trading/ledger; streaming/event store for order/market data; time-series storage for ticks.
-
Architecture and APIs
-
Service decomposition; synchronous vs asynchronous APIs.
-
Message queues, event sourcing, idempotency design.
-
Consistency and Latency
-
Guarantees for order state vs portfolio views (strong vs eventual consistency).
-
Latency targets for quotes, order acks, fills.
-
Scale, Reliability, and Failures
-
Market open surges; backpressure strategies.
-
HA/DR design, rate limits, circuit breakers.
-
Failure modes: market data outage, exchange issues, clearing delays.
-
Observability and Compliance
-
Metrics, tracing, centralized logs.
-
Audit/compliance logging (immutable/WORM), SOX/SEC/FINRA considerations.
-
Extensibility
-
How to add options (OPRA, OCC, risk/margin) or crypto (wallets, custody, 24/7).