#34 Low-Latency Streaming
Global Stock Price Viewer
Push live prices for thousands of stocks to millions of screens around the world with delays of well under a second.
What is being asked
Design a live quote service. Exchanges emit a flood of price updates; each user watches a handful of symbols and should see changes almost as they happen.
Requirements
Functional
- Subscribe to a list of symbols and receive live prices.
- Show the latest price immediately on opening the page.
- Historical charts.
Non-functional
- Hundreds of thousands of updates per second at the source.
- Millions of concurrent connections.
- Low latency worldwide; a missed intermediate tick is acceptable, a stale final price is not.
Design
- Feed handlers convert each exchange's format into a common tick and publish to a stream partitioned by symbol.
- The latest price per symbol is kept in a cache, so a new viewer gets a value at once.
- A fan-out tier conflates: it sends at most a few updates per symbol per second, always the most recent, since nobody can read faster.
- Edge servers near users hold the WebSocket connections and keep a map from symbol to subscribed connections. They subscribe upstream only to symbols someone there is watching.
Key decisions and trade-offs
- Conflation cuts volume by orders of magnitude and protects slow clients. Professional traders who need every tick use a different, costlier product.
- Push at the edge. Terminating connections regionally keeps the last hop short; the backbone carries one copy per symbol per region, not one per user.
- Slow consumers. If a client cannot keep up, drop intermediate updates for it rather than queueing without bound.
- Snapshot then stream. Send the cached price first, then live updates with sequence numbers so the client can detect a gap and ask for a fresh snapshot.
Follow-up questions
- How do you handle a symbol that half of all users watch during a crash?
- How would you reconnect a million clients after an edge server restarts?
- How are historical candles built from the tick stream?
- What changes for delayed quotes for unpaid users?