Skip to content
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

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
1feeds → handler · AAPL 182.34A trade prints in New York. The exchange multicasts it on lines A and B with sequence number 88,412.1 / 5

The numbers, at a glance

Ticks that reach viewersout of every 20 raw ticks
1 sent on19 folded into the latest
Messages out a second10 million viewers, 20 symbols each
A gateway reading the feedshare of one server spent reading updates
Reading all 600,000 ticks a second would take 60%.

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.

Short polling
Too slow, too costly
GET /quotes every 2 s
20 cache reads
mostly “no change”
+ Plain HTTP.− Up to 2 s old; 5M req/s.
Push every tick
Floods everyone
600,000 ticks/s
every gateway reads all
40 msgs/s per viewer
+ Exact and instant.− 400M messages/s.
Conflated push
Our pick
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.

Stage 1 · ≈ 1,000 viewersMake it work
Feed handler
CacheApp server
Viewers
One handler fills a cache; apps poll every 2 s.
Stage 2 · ≈ 10,000 viewersPush prices
Feed handlersTick bus
GatewaysCache
Viewers
A tick bus and WebSocket gateways; nothing is sent when nothing changes.
Stage 3 · ≈ 1,000,000 viewersConflate
Feed handlersTick busHistory
ConflatorFan-out
GatewaysCache
Viewers
Latest price every 250 ms, fanned out to every gateway; history stored.
Stage 4 · ≈ 10,000,000 viewersGo worldwide
Feed handlersTick bus × 64History
6 regionsConflatorFan-out × 64
GatewaysCacheAuth
Viewers
64 partitions by symbol, 6 regions, entitlements in the token.
Was this walkthrough useful?Your vote tells us what to improve next.