Problem
Design the system that streams live stock prices to millions of users and computes real-time portfolio P&L.
Requirements
Functional:
- Live price updates for 5000+ NSE/BSE scrips
- Per-user portfolio P&L updated in real time
- Price alerts: notify when stock crosses user-set threshold
- Historical price charts (1D, 1W, 1M, 1Y)
Non-functional:
- 15M users, 2M with active sessions at market open
- Price update latency < 500ms from exchange tick
- Price alert delivery < 2s
Discussion points
- Exchange feed ingestion: FIX protocol → Kafka
- Fan-out challenge: 2M users watching RELIANCE simultaneously
- WebSocket vs SSE for price delivery
- P&L computation: push (per tick) vs pull (on request)
- Alert engine: sorted set in Redis keyed by threshold price