SD-44 · Back to the write-up
Design a Live Stock Prices
Ticks flow from exchanges onto a bus split by symbol; conflators keep the latest price every 250 ms, and regional gateways push small frames to millions of WebSockets.
Follow a request
A trade reaches screens
Open a watchlist
Keep the cache fresh
A gateway dies
A feed gap
Exchanges
Ingest
Each region
Viewers
Exchange feedsLines A + B
Feed handlersNormalize
Tick bus64 partitions
Price historyTicks, candles
ConflatorEvery 250 ms
Last-price cache60,000 keys
GatewaysWebSockets
ViewerWeb or app
The numbers, at a glance
1 sent on19 folded into the latest
5M req/sPoll 2 s
40M frames/sPush, conflated
400M msgs/sEvery tick
3% conflated feedone gateway
A price, in order
The 250 ms window is the largest part of the delay; network and processing add about 80 ms in a nearby region.
Exchange
Feed handler
Tick bus
Conflator
Gateway
Viewer
1 trade, seq 88,412
2 normalized tick
3 ticks for partition 17
4 latest, end of window
5 sub [AAPL, …]
6 frame { AAPL 182.34, seq 9,031 }
RequestResponseAsync, does not block
How prices reach the screen
The decision this question is really about.
GET /quotes every 2 s
20 cache reads
mostly “no change”
+ Plain HTTP.− Up to 2 s old; 5M req/s.
600,000 ticks/s
every gateway reads all
40 msgs/s per viewer
+ Exact and instant.− 400M messages/s.
latest per symbol / 250 ms
fan-out by symbolregional gateways
1 frame per viewer
+ Fresh within 330 ms; 4 frames/s.− Gateways track subscriptions.
How it grows
Add a box only when a number forces you to. Highlighted boxes are new at each stage.
Feed handler
CacheApp server
Viewers
Feed handlersTick bus
GatewaysCache
Viewers
Feed handlersTick busHistory
ConflatorFan-out
GatewaysCache
Viewers
Feed handlersTick bus × 64History
6 regionsConflatorFan-out × 64
GatewaysCacheAuth
Viewers
Was this walkthrough useful?Your vote tells us what to improve next.