Design Robinhood (Stock Trading Platform)
DifficultyHard | HelloInterview: problem breakdown
Problem Statement
Design a retail stock trading platform where users can view real-time stock quotes, place buy/sell orders, and see their portfolio value. Orders must be routed to a market and confirmed back to the user.
๐Real-world: The GameStop short squeeze (January 2021) exposed what's really under a trading app. As GME volume exploded, Robinhood abruptly restricted buying โ not out of malice but because its clearinghouse (the NSCC) demanded a ~$3 billion collateral deposit overnight to cover the T+2 settlement risk of all those pending trades; Robinhood didn't have it and had to halt buys, drawing congressional hearings. The systems lesson: a trading platform is mostly a correctness-and-consistency problem, not a scale problem โ orders are money, so you need a single-threaded matching/sequencing path per symbol, event sourcing for an immutable order ledger, idempotency to prevent double-execution, and strong consistency everywhere. "Eventually consistent" is acceptable for a feed; for someone's brokerage balance it's a lawsuit. Real-time quotes fan out over WebSockets, but the order path is where the rigor lives.
Requirements
Functional
- Real-time stock quotes (price, volume, bid/ask)
- Place market/limit/stop orders
- Order status updates (pending, filled, cancelled)
- Portfolio view (positions, P&L, history)
- Watchlist management
Non-Functional
- Thousands of tickers, millions of users
- Quote latency: < 100ms (near real-time tick data)
- Order placement: < 500ms to confirmation
- Market hours: peak load 9:30am-4pm ET on trading days
- Regulatory: FINRA, SEC compliance; audit trail for every trade
Core Design
Real-Time Quote Data
Stock prices update multiple times per second during market hours. Source: market data feeds (NYSE, NASDAQ via OPRA, SIP). These provide raw tick data.
Market Data Feed โ WebSocket receiver
โ
Quote Normalizer (convert to unified format)
โ
Kafka (topic: quotes, partitioned by ticker)
โ
Quote Cache (Redis: latest price per ticker, TTL 1s)
โ
Quote Service โ SSE/WebSocket โ User devicesFor 5000 tickers ร 100k active users subscribed to quotes: use pub/sub. Each quote server subscribes to Kafka, fans out to its connected clients.
Candles (OHLCV charts)1-minute aggregation from tick stream via Flink stream processor โ stored in TimescaleDB.
Order Routing
Robinhood is a broker-dealer. It doesn't operate its own exchange. Orders are routed to market makers (Citadel Securities, Virtu) or exchanges.
User places order โ Order Service
โ
Order Validation:
- Account balance / buying power check
- Position limits
- Pattern Day Trader checks
โ
Order DB (write: PENDING)
โ
FIX Protocol message โ Market Maker / Exchange
โ (async fill notification)
Order fill webhook โ Update Order DB (FILLED)
Update Portfolio DB
Notify user (WebSocket)FIX ProtocolFinancial Information eXchange โ the industry standard for order routing. Messages include order ID, ticker, quantity, side (buy/sell), order type.
Portfolio Calculation
portfolio_positions(user_id, ticker, quantity, avg_cost_basis)
โ P&L = (current_price - avg_cost_basis) ร quantity
Real-time portfolio value: quantity ร current_quote (from Redis cache)
Historical P&L: store daily portfolio snapshotsArchitecture
Market Data Feed โ Kafka โ Quote Cache (Redis) โ WebSocket โ Users
Order Flow:
User โ Order Service โ Validation โ Order DB โ FIX โ Market
โ (fill callback)
Portfolio Service โ User notification
Trade History DB (append-only)
Compliance:
Every order event โ Audit Log (immutable, off-system) โ FINRA reportingKey Design Decisions
| Decision | Choice | Reason |
|---|---|---|
| Quote delivery | Kafka + SSE/WebSocket | Millions of quote updates/s; fan-out |
| Order storage | PostgreSQL (ACID) | Financial transactions need strong consistency |
| Portfolio value | Real-time from Redis quote cache | Sub-second portfolio refresh |
| Audit log | Append-only, separate system | Regulatory requirement; cannot be altered |
| Order routing | FIX protocol | Industry standard; required by exchanges/market makers |
Security Considerations
| Threat | Mitigation |
|---|---|
| Unauthorized order placement | Re-auth for large orders; session token validation |
| Market manipulation (wash trading) | Pattern detection; account surveillance |
| Pattern Day Trader rule (PDT) | Automated PDT flag; block 4th same-day trade if under $25k |
| Account takeover โ unauthorized trades | Device trust; step-up auth for order placement; trade confirmation email |
| Data leakage (position disclosure) | Portfolio data is highly sensitive PII; row-level security in DB; encrypt at rest |
| Front running | Separate order flow from market data feed; no internal leakage of pending orders |
| Regulatory audit | Immutable order log; FINRA Rule 17a-4 compliance (non-erasable, time-stamped records) |
Interview Tips
knowing the industry standard for order routing is a differentiator.
quotes are eventually consistent (1-second staleness is fine); orders are strongly consistent (no double fills, no lost orders).
every order event, every portfolio change, goes to an immutable audit log. Mention FINRA Rule 17a-4.
discuss how you handle the 9:30am open (all US traders placing orders simultaneously).