Design a Weather App
Understanding the Problem
🌦️ What is a weather app? A weather app shows the current conditions, an hourly forecast and a multi-day forecast for wherever you are, plus warnings when something dangerous is coming. The app doesn't make forecasts itself. It collects data from weather services like the US National Weather Service (NWS) and commercial providers, reshapes it, and serves it to a very large number of people asking very similar questions.
The usual framing in interviews: "Our data comes from the NWS, which updates hourly. Users should never see data more than 10 minutes older than what the source has published. We also want to add third-party sources." That makes this a data ingestion and caching problem much more than a user-facing one.
Functional Requirements
Core Requirements
- Users should be able to see current conditions, an hourly forecast (48 hours) and a daily forecast (7 days) for their current location or a searched place.
- Users should be able to save locations and receive push alerts for severe weather (tornado or flood warnings) at those locations.
- The system should ingest data from the NWS and from additional third-party sources, and combine them into one view.
Below the line (out of scope)
- Radar and satellite map tiles (a separate tiling pipeline).
- Running our own forecast models.
- Historical weather and climate data.
Non-Functional Requirements
Ask your interviewer for numbers. Ours: 50 million daily active users, each opening the app about 3 times a day. Coverage is the US to start.
Core Requirements
- Data shown to users should be no more than 10 minutes behind the latest data the source has published.
- Reads should be fast: under 200 ms for the forecast screen, globally cacheable.
- The system should stay up when a source is slow or down, serving the last good data with a clear "updated at" time.
- Severe weather alerts should reach affected users within a minute or two of being issued.
- The system should handle spikes: during a hurricane, traffic in the affected region can jump 10x or more.
Below the line (out of scope)
- Global coverage on day one (the design generalizes, sources differ per country).
- Exact-to-the-second freshness. 10 minutes is the requirement.
The arithmetic changes the design. 50M users × 3 opens = 150M forecast requests per day, about 1,700 per second on average and maybe 20k per second at a storm peak. But the number of distinct answers is small. The NWS forecasts on a grid of roughly 2.5 km cells. The continental US is about 8 million km², so that's on the order of 1.3 million grid cells. Every user in the same cell gets the same forecast.
Once you see that the output is keyed by grid cell, not by user, the problem gets easy. We precompute one forecast document per cell, about 1.3M of them, and serve them from a cache. User traffic becomes a cache-hit-rate problem, and the hard part moves to ingestion.
Storage is small too. A cell's document with 48 hourly and 7 daily entries is roughly 10 KB of JSON, so 1.3M cells is about 13 GB. It fits in a modest Redis cluster or a single DynamoDB table with room to spare.