π Problem Description
Design a real-time stock price viewing service that streams live prices to millions of users. Show current prices, price changes, charts, and support watchlists. Handle high-frequency updates during market hours.
π€ Use Cases
1.
User wants to opens stock page so that sees live price updating in real-time
2.
User wants to views watchlist so that sees all watched stocks with live prices
3.
User wants to views chart so that sees historical and real-time price chart
4.
System wants to receives market data so that broadcasts to all subscribed users
β Functional Requirements
- β’Real-time stock price streaming
- β’Price change ($ and %) from open
- β’Bid/ask prices and volume
- β’Intraday, 1W, 1M, 1Y charts
- β’Watchlists with multiple stocks
- β’Search for stocks by symbol/name
- β’Price alerts
β‘ Non-Functional Requirements
- β’Price update latency < 100ms from exchange
- β’Support 10M concurrent users during market hours
- β’Handle 10K price updates per second
- β’99.9% availability during market hours
β οΈ Constraints & Assumptions
- β’Market data licenses required
- β’Updates only during market hours
- β’Historical data for charting needed
π Capacity Estimation
π₯ Users
10M concurrent during peak hours
πΎ Storage
100GB for historical prices + real-time buffer
β‘ QPS
Inbound: 10K updates/sec, Outbound: 10M WebSocket connections
π Bandwidth
50TB/day during market hours
π Assumptions
- β’ 10K ticker symbols
- β’ Updates every 100ms during trading
- β’ 10M concurrent users watching prices
- β’ Average user watches 10 stocks
π‘ Key Concepts
CRITICAL
Pub/Sub for Price Distribution
Use Kafka topics per symbol for scalable fan-out.
CRITICAL
WebSocket Fan-out
Maintain millions of WebSocket connections with subscription management.
HIGH
Time-Series Storage
Store OHLCV data for charting in InfluxDB or TimescaleDB.
HIGH
Throttling
Batch rapid updates to reduce client message frequency.
π‘ Interview Tips
- π‘Start with the real-time streaming architecture
- π‘Discuss the fan-out pattern for subscriptions
- π‘Emphasize the low-latency requirements
- π‘Be prepared to discuss time-series storage
- π‘Know the tradeoffs between push and pull
- π‘Understand the market data feed structure