Design a Live Market Data Feed for a Financial Dashboard
System DesignModel answerLast updated
Design a system that streams real-time asset prices to millions of concurrent users with sub-100ms end-to-end latency.
Design a Live Market Data Feed for a Financial Dashboard
You're building the backend for a financial data platform that shows live prices for hundreds of tradeable assets — think stocks, FX pairs, or commodities. A front-end dashboard displays the current price of each asset and a 24-hour price chart. Prices must update automatically as market conditions change, no page refresh required.
Your system receives raw price ticks from several third-party market data providers via WebSocket or REST streams. Your job is to ingest those ticks, compute a unified price, and push updates out to a very large number of simultaneous browser clients with minimal delay.
Requirements
Functional
- Users can load a dashboard listing all supported assets and their current prices.
- Prices refresh automatically in real time — no polling from the user's browser.
- The system stores a rolling 24-hour price history at a reasonable granularity (e.g., 5-minute OHLCV candles) to power the chart view.
Non-Functional
- Scale: 5 million concurrent connected clients at peak.
- Latency: Price updates must reach clients within 100ms of being received from upstream providers.
- Availability: The system must stay up continuously. Occasionally dropping a single price tick is tolerable; extended outages are not.
- Consistency: All users should see roughly the same price at any given moment. Small per-client jitter is acceptable.
What your answer should address
- Ingestion: How do you reliably consume tick streams from multiple upstream providers that each have their own protocols and failure modes?
- Normalization and aggregation: How do you reconcile prices from different sources into a single authoritative price per asset?
- Fanout: How do you push updates to 5 million clients without melting your infrastructure?
- Storage: What databases do you use for current prices versus historical candle data, and why?
- Handling volatility spikes: A sudden market event can cause tick volume to spike 50–100x above normal. How does your design hold up?
Aim for a structured walkthrough: size the problem first, then describe each layer of the architecture, call out your key technology choices and the trade-offs behind them, and flag the places where the design could break under stress.
Hints
Hint 1
Start by doing the fanout math before picking any technology. Five million clients receiving updates once per second is a fundamentally different problem than five million ticks per second arriving from upstream — figure out which side dominates your infrastructure cost, because the answer shapes every subsequent decision.
Hint 2
Upstream tick rate and client update rate don't have to be the same. If prices change 500 times per second but a human eye can only perceive about 10 updates per second, you can decouple the two with a technique called conflation: always forward the latest state rather than every intermediate tick. This keeps client-facing load roughly constant even during volatility spikes.
Hint 3
The bottleneck in a push-based system at this scale isn't the message broker — it's the final hop from your servers to 5 million open sockets. Think about how many WebSocket gateway nodes you need, how they learn about new prices (they shouldn't each be a direct subscriber to every upstream event), and what happens to a slow client whose buffer fills up.
Model answer
Hard Try it yourself first — then compare your approach, complexity and edge cases.
Approach
1. Size the Problem First
Before drawing any architecture boxes, pin down the numbers that actually drive the design.
Upstream ingestion: 10 providers × 500 asset pairs each, normal load around 50,000 ticks/second in aggregate. A volatility spike at 100× means 5 million ticks/second. This is large but very manageable for a Kafka cluster.
Client fanout: 5 million concurrent WebSocket connections. If each client receives one update per second containing ~50 changed prices at ~1–2 KB compressed, that's roughly 5–10 GB/s of outbound traffic. At 10 updates/second for a premium tier (say 10% of users), you double that. Fanout dominates. Ingestion is cheap by comparison.
Latency budget (100ms end-to-end):
| Stage | Budget |
|---|---|
| Ingest + broker write | ~15ms |
| Aggregation | ~5ms |
| Internal pub/sub | ~5ms |
| Gateway to client | ~50ms |
| Network (last mile) | ~25ms |
The most important architectural decision follows directly from this math: decouple upstream tick rate from client update rate using conflation — always send the latest snapshot, never replay every tick. This keeps client-facing load flat regardless of what upstream is doing.
2. API Design
Push beats pull at this scale. Five million clients polling every second is 5 million HTTP requests/second with TLS overhead and up to 1 second of added latency baked in. WebSockets with SSE as a fallback give you one persistent connection per client and server-initiated delivery.
WS /v1/stream
→ {"op":"subscribe","symbols":["BTC-USD","ETH-USD"]}
← {"type":"snapshot","seq":1100,"ts":1718000000100,"prices":{"BTC-USD":"67012.55",...}}
← {"type":"delta","seq":1101,"ts":...,"prices":{"BTC-USD":"67018.20"}}
GET /v1/prices # initial page load, CDN-cached ~1s
GET /v1/prices/{symbol}/candles?range=24h # chart data, CDN-cached
Two design details worth calling out:
- Sequence numbers let a client detect a gap. The correct response is to wait for the next snapshot, not to request a replay — dropped ticks are acceptable and the next update supersedes them anyway.
- Always send a full snapshot on connect, so reconnects are self-healing with no special recovery logic on the client.
3. Architecture Walkthrough
Providers (WS/REST)
→ Ingestion connectors (one service per provider, multi-AZ pairs)
→ Kafka "raw-ticks" topic (partitioned by symbol)
→ Normalizer / Aggregator (stateful stream processor, per partition)
→ Kafka "market-prices" topic
→ Candle builder → ClickHouse / TimescaleDB
→ Redis current-price cache
→ Internal pub/sub (Redis Pub/Sub or NATS)
→ WebSocket gateway fleet (~100 nodes, ~50k connections each)
→ L4 load balancer / CDN edge
→ 5M clients
Ingestion connectors are thin, one service per upstream provider. They handle that provider's quirks — heartbeat formats, sequence gap recovery, REST snapshot + WebSocket diff resync — stamp a recv_ts, and produce raw events to Kafka. Thin connectors are intentional: doing heavy work here risks backing up the socket and causing the upstream provider to drop you. Run two active replicas per provider in separate availability zones and deduplicate downstream by (provider_id, provider_seq).
Normalization and aggregation runs as a Kafka Streams or Flink job, partitioned by symbol so all ticks for a given asset go to the same processor. Normalization handles the boring but important work: canonical symbol names (XBT/USD → BTC-USD), decimal arithmetic instead of floats, UTC timestamps, and quote-currency conversion. The aggregator fires every 100ms, computes a volume-weighted median across providers whose last update is fresh (within 5 seconds), and publishes only if the price changed. Volume-weighted median beats simple VWAP here because it's more resistant to a single bad-data venue without being expensive to compute. The aggregator's entire state fits in memory and can be rebuilt in seconds from Kafka, so hot standbys are cheap.
Fanout is the hardest part. The naive approach — one Kafka consumer or Redis subscriber per gateway node, each holding 50k connections — works but creates a lot of duplicated work. The better model is two-tier:
- The aggregator publishes one compact batch every 100ms to a Redis Pub/Sub channel. That batch contains all changed prices: a few kilobytes at most.
- Only the ~100 gateway nodes subscribe to Redis. Redis fans out to 100 subscribers, not 5 million.
- Each gateway receives the batch, determines which of its connected clients care about which symbols, serializes and compresses once per tier/symbol-set, and writes the same bytes to potentially thousands of sockets.
For the gateway's own connections, use an epoll-based runtime (Go, Netty, or Rust async) targeting around 50,000 connections per node. At ~15–20 KB of memory per connection that's ~750 MB per node, well within reason.
Slow clients are a real operational hazard. If a client isn't draining its buffer, don't queue messages — overwrite the pending message with the newer state. This is conflation at the connection level and it ensures one slow mobile client can't cause unbounded memory growth on a gateway node.
4. Storage
- Redis: current price per symbol (a hash with price, bid, ask, timestamp, 24h change) plus the last 288 five-minute candles per symbol. This serves the dashboard's initial load instantly without touching the time-series DB.
- ClickHouse or TimescaleDB: durable OHLCV candles at 1-minute, 1-hour, and 1-day granularity with automatic rollups and TTLs. The candle builder is a separate Kafka consumer and is entirely off the hot path — a slow write here has zero impact on real-time latency.
- S3 / object storage: raw ticks archived as Parquet for backfill, audits, and ML feature pipelines.
5. Handling Volatility Spikes
A 100× tick surge hits the ingestion and aggregation layers, not the clients, which is exactly where you want it.
- Kafka absorbs the burst. Size partitions and brokers for peak throughput. Use producer batching (
linger.ms1–5ms) and compression. - The aggregator remains O(1) for output regardless of input rate. However many ticks arrive, it still emits one batch every 100ms. Fanout load is completely stable.
- If aggregator consumer lag grows, skip to the latest offset per partition rather than processing stale ticks in order. A tick that is 30 seconds old is less useful than the one that just arrived.
- Gateway memory pressure: since conflation is already in place, each connection holds at most one pending message. Spike or not, the per-connection footprint doesn't change.
- Circuit breaker on stale providers: if a provider goes quiet during a volatile period (they do this — exchanges sometimes throttle or disconnect during flash crashes), exclude them from the median calculation rather than serving a frozen price.
Common Mistakes to Avoid
- Using HTTP long-polling or client-side polling instead of WebSockets. At 5M clients the request overhead alone exceeds the latency budget.
- Replaying every tick to clients instead of conflating. Upstream tick rate and client update rate must be decoupled.
- Putting Redis Pub/Sub between the aggregator and every gateway node without thinking about fan-out to connections. Redis should fan out to a small number of gateway processes, not directly to millions of clients.
- Using floats for prices. Financial data requires exact decimal arithmetic; floating-point rounding errors in prices are a correctness bug, not a performance trade-off.
- Forgetting the thundering herd on reconnect. After a gateway node failure, all its clients reconnect simultaneously. Jittered exponential backoff on the client and a reconnect hint before draining a node are both necessary.