Design CoinSwitch's Real-Time Price Aggregation Service Across 10 Exchanges
Problem
Design a price aggregation service that consumes live price feeds from 10 crypto exchanges and serves a unified best-price view to CoinSwitch users.
Requirements
Functional:
- Aggregate BTC/INR, ETH/INR, etc. prices from 10 exchange WebSocket feeds
- Compute best bid (highest buy price) and best ask (lowest sell price) across all exchanges
- Serve aggregated price to 5M users with < 500ms latency
- Price history for charting (1m, 5m, 1h candles)
Non-functional:
- 10 exchanges × 100 price updates/sec = 1000 inbound events/sec
- Fanout to 5M user sessions
- 99.9% uptime — exchange feed drops should not cause outage
Discussion points
- Exchange feed ingestion: WebSocket reconnect with exponential backoff
- Aggregation logic: per-pair sorted map of (exchange → price)
- Fanout: Redis Pub/Sub vs Kafka → WebSocket gateways
- Stale price handling: if exchange feed drops, mark price as stale after TTL
- OHLCV candle computation: streaming aggregation with time windows
added …