Build a Scheduled Hourly Feed of Public Weather Observations
System DesignModel answerLast updated
Design a pipeline that polls a public weather provider for thousands of locations each hour, stores normalized history without duplicates, and serves fresh data reliably.
Problem
Your team needs an internal service that pulls weather data from a public government provider (for example, the U.S. National Weather Service API, or a comparable source) once per hour and makes it available to other teams. An external-facing API is an optional extension.
What the service must do
Functional
- Poll the provider every hour for every supported location (weather stations or grid points).
- Convert the provider's response format into one internal schema.
- Keep historical data so it can be queried and used for analytics.
- Serve the data through an API or bulk export, with a clear and predictable freshness promise.
Non-functional
- Stay within the provider's rate limits, terms of use, and robots rules.
- Be reliable, using retries with backoff.
- Ingest idempotently, so retries and replays never produce duplicate records.
- Alert when data is missing or late.
Working assumptions (you can adjust them)
- About 10,000 locations.
- Each location produces one new reading per hour.
- The provider is occasionally unreliable and sometimes returns incomplete payloads.
What to cover in your answer
- Scheduling and crawling architecture
- Storage choices and schema
- Freshness guarantees and backfill approach
- Rate limiting, retry policy, and idempotency
- Monitoring, alerting, and data quality checks
Hints
Hint 1
Do the arithmetic first: 10,000 fetches per hour is under 3 requests per second. Let that conclusion shape how much infrastructure you propose, and spend your effort on correctness instead.
Hint 2
Find a natural key for a reading, such as (location, observed hour). If every write is an upsert on that key, retries, duplicate queue deliveries, and backfills all converge to a single row.
Hint 3
Separate fetching from parsing by storing raw responses. Also keep a task ledger of expected (location, hour) work: it drives retries, backfill, and the completeness alerts.
Model answer
Easy Try it yourself first — then compare your approach, complexity and edge cases.
1. Clarify and size the problem
Questions to settle up front:
- Observations, forecasts, or both? Observations are append-only facts; forecasts get revised. I will treat observations as the core and forecasts as an extension keyed by issue time.
- Freshness target: data for hour H is queryable by H+15 min for 99% of locations, and 100% by H+60 min or explicitly flagged missing.
- Consumers: internal services first, with an optional external API that would need its own auth and rate limits.
- Retention: keep everything, with recent data in fast storage.
Estimates
| Item | Number |
|---|---|
| Fetches | 10,000/hour, about 2.8 req/s averaged (more with retries and backfill) |
| Raw payload | 2-5 KB each, about 50 MB/hour, about 400 GB/year before compression |
| Normalized rows | 10k x 24 x 365, about 88M rows/year at about 200 B, roughly 20 GB/year |
| Reads | Mostly "latest for location X", easily cached |
The scale is small. The difficulty is correctness, politeness toward the provider, and noticing gaps. Saying this out loud avoids over-engineering.
2. Architecture
Scheduler -> Queue -> Crawler workers -> Raw store (object storage)
^ | token bucket |
| v v
crawl_tasks <--- retry / DLQ Normalizer -> Observations DB -> Cache -> Query API
Completeness checker -> alerts + backfill \-> Parquet export to warehouse
- Scheduler runs every minute (single cron or leader-elected). It creates task rows for the upcoming hour and enqueues those that are due. Each location gets a stable hash-based minute offset, for example between :05 and :35, after the provider normally publishes. This prevents a burst at the top of the hour.
- Crawler workers are stateless. They take a rate-limit token, fetch with strict timeouts, use conditional requests (ETag or If-Modified-Since) when supported, save the raw body, and emit a "fetched" event.
- Normalizer applies a versioned adapter for the provider's format, converts to SI units, validates, and upserts. Since raw data is kept, a parser bug is fixed by replaying stored payloads rather than re-hitting the provider.
- Query API reads from cache and falls back to the database.
3. Storage and schema
- locations: id, provider identifiers, lat/lon, timezone, active flag, priority.
- raw_responses (object storage): immutable, keyed by provider/location/date-hour/fetch_id, gzip. Cheap and replayable.
- observations (time-series table, e.g. Postgres with Timescale; a wide-column store only at much larger scale): primary key
(location_id, observed_hour); columns for temperature, humidity, wind speed and direction, precipitation, pressure, condition code, plussource_ts,ingested_at,quality_flags,raw_ref,schema_version. - forecasts: key
(location_id, issued_at, valid_hour)so revisions are preserved. - crawl_tasks:
(location_id, target_hour, endpoint)with status, attempt count, last error, and next attempt time. This ledger is the backbone for retries, backfill, and completeness checks.
Missing fields are stored as null with a flag, not by dropping the row.
4. Rate limiting, retries, idempotency
Rate limiting
- A global token bucket in Redis shared by all workers, set well under the provider's published limit (say 5 req/s against a 2.8 req/s need) to leave room for retries.
- Backfill draws from a separate, lower-priority budget so it cannot starve live crawling.
- On 429/503 or a
Retry-Afterheader, pause the bucket globally (circuit breaker) instead of per worker. - Send an identifying User-Agent with contact details, and follow the provider's terms and caching rules.
Retries
- Exponential backoff with full jitter (about 30s, 1m, 2m, 5m), capped by the hour's freshness window.
- Retryable: timeouts, 5xx, 429. Non-retryable after N attempts: 404 and malformed payloads, which go to a dead-letter queue and set a quality flag.
- Partial payloads: store the valid fields, flag the row, and schedule a later re-fetch because observations are often filled in late.
Idempotency (needed because queues deliver at least once)
- Writing to
(location_id, observed_hour)is an upsert, so duplicates converge. - Guard the upsert: update only if the incoming
source_tsis newer or the quality is better, so a degraded late response cannot overwrite a good row. - Tasks are deduplicated on
(location_id, target_hour, endpoint), so scheduler restarts are safe. - A content hash on the raw payload lets us skip reprocessing when nothing changed.
5. Freshness and backfill
- Publish the SLO and expose
observed_atandingested_atin every response, plus a status endpoint with per-hour completeness. - A completeness checker runs every 5 minutes, compares expected (location, hour) pairs against stored rows, and re-enqueues gaps.
- Backfill after outages or when adding locations walks the task gaps through the provider's historical endpoint at low priority. Beyond the provider's lookback window, mark the hour permanently missing (or fill from a secondary source and label it).
6. Monitoring and data quality
- Metrics: percentage of locations complete per hour, p50/p99 ingest lag (ingested_at minus observed hour), fetch success rate, retry and DLQ depth, token bucket utilization, parser error rate.
- Alerts: completeness below 99% at H+20 min, lag SLO breach, provider error rate spike, DLQ growth, a location silent for several hours.
- Quality checks: range checks (e.g. humidity 0-100, plausible temperature), spike/jump detection versus the previous hour, stale timestamps, unit sanity, and schema drift detection that fails loudly on unexpected fields.
- Observation of a provider outage should trigger a status banner and keep serving the last known value with its age visible.
7. Trade-offs and common mistakes
- Over-building for scale: Kafka clusters and sharded stores are unnecessary at 3 req/s.
- Firing all requests at :00, which hurts both the provider and your own freshness.
- Parsing inline with fetching, so a parser bug forces re-crawling.
- Using insert instead of upsert, creating duplicates on retry.
- Treating "no new data yet" as an error rather than a late arrival to be retried.
- Ignoring the provider's terms or User-Agent requirements.
- No ledger of expected work, which makes missing data invisible.
Possible follow-ups: adding more providers (adapter interface plus per-provider budgets), moving to sub-hourly data, multi-region deployment, and serving an external API with per-key quotas.