Skip to content
SD-36 · Back to the write-up

Design a Weather App

Snap positions to 5 km cells, ingest the provider’s feed on a schedule, and let a CDN and a cache answer almost every request.

Follow a request

Phones
Edge
Services
Data + provider
Mobile appSnaps to a cell
Push servicesApple, Google
CDNCell URLs
Load balancerSpreads traffic
Ingest workersEvery run
Forecast APIStateless
Forecast cacheHot cells
Alert workersFan-out
Weather providerBulk feed
Forecast storeBy cell
SubscriptionsCell → devices
1client → cdn · GET /forecast/u0bmpA cell in the countryside that this edge has not seen since the last update.1 / 8

The numbers, at a glance

Of every 100 requests in a storm……only 1 reaches the forecast store
1 store read99 from CDN or cache
Provider calls per secondAt the 50,000 req/s morning peak
The whole dataset is smallForecast store against one cache node’s memory
So caching every hot cell in memory is cheap; the hard part is the key.

A forecast request, in order

Edge and cache miss shown. On an edge hit, steps 2 to 9 disappear; on a cache hit, steps 5 and 6 do.

Mobile app
CDN
Load balancer
Forecast API
Forecast cache
Forecast store
1 GET /forecast/u0bmp
2 forward (collapsed)
3 route
4 GET u0bmp
5 miss
6 GET current version
7 2 KB forecast
8 SET until next update
9 200 + max-age
10 200
11 200 forecast
RequestResponseAsync, does not block

What a forecast is keyed by

The decision this question is really about.

Exact coordinates
Uncacheable
?lat=48.85661&lon=2.35222
Cache hit ≈ 10%
Provider over its cap
+ Precise.− Every key unique; misses call the provider.
Nearest city
Too coarse
/forecast/city/2988507
Cache hit ≈ 99%
Mountain gets city weather
+ Few keys.− Wrong weather 40 km out.
5 km grid cell
Our pick
/forecast/u09tv
CDN 80%Cache 95%
Store reads ≈ 1%
+ As precise as the data, 95% hits.− A cell shares one forecast.

How it grows

Add a box only when a number forces you to. Highlighted boxes are new at each stage.

Stage 1 · ≈ 1,000 req/sMake it work
Mobile app
App server
Weather provider
One server calls the provider for every exact position.
Stage 2 · ≈ 10,000 req/sCache by cell
Mobile app
Load balancer
Forecast API × N
Forecast cacheWeather provider
Snap to 5 km cells, cache by cell, more servers.
Stage 3 · ≈ 50,000 req/sIngest, don’t fetch
Mobile app
Load balancer
Forecast API × NIngest workers
Forecast cacheForecast storeWeather provider
Pull the bulk feed each run into our own store.
Stage 4 · ≈ 200,000 req/s stormEdge and alerts
Mobile appPlace search
CDN
Load balancer
Forecast API × NIngest workersAlert workers
Forecast cacheForecast storeSubscriptions
CDN for spikes, place search, warning fan-out.
Was this walkthrough useful?Your vote tells us what to improve next.