KatInterview

Build a Near-Real-Time Environmental Data Feed API

System DesignModel answer
HardModel answerSystem Designingestion-pipelinecachingrate-limiting

Last updated

Design a platform that polls an external sensor API hourly for ~2,000 U.S. locations and serves current readings with a strict 10-minute freshness guarantee.

Scenario

A third-party environmental sensor network publishes hourly data snapshots for roughly 2,000 monitoring stations across the United States. Your company wants to expose this data to internal dashboards and external clients through a clean API that always returns the current reading for any station.

Non-negotiable requirement: every response must reflect a reading no older than 10 minutes past the provider's most recent publish time.


What You Need to Design

1. High-Level Architecture

Sketch the major components: how data gets in, where it lives, how it gets cached, and how clients read it. Identify the scheduler or orchestrator that drives ingestion.

2. API Contract

Define the endpoint(s) clients will call. At minimum, support lookup by station ID and by geographic coordinates (return the nearest covered station). Include:

  • Request parameters and response schema
  • Freshness metadata in the response
  • Versioning strategy
  • All meaningful error cases (missing station, stale data, client rate limits, etc.)

3. Data Model and Storage

Choose your database(s). Define the schema for stations and for time-series observations. Explain your partitioning and retention approach, your indexing choices, and how raw upstream payloads are preserved for replay or auditing.

4. Ingestion Pipeline

Walk through every stage from "provider publishes new data" to "data is queryable":

  • How do you detect a new publish?
  • How do you fan out work across ~2,000 stations while staying within the provider's rate limit (assume ~20 req/s)?
  • How do you handle retries, deduplication, and idempotent writes?
  • How do you backfill gaps caused by transient failures without starving the current hour's ingestion?

5. Caching and Invalidation

Describe your full caching stack (in-process, distributed cache, optional CDN). Explain TTL choices, how cache entries get invalidated when new data arrives, and where the read API enforces the freshness hard limit.

6. Scaling and Capacity

Estimate writes per second, peak read QPS, hot data set size, and annual storage. Show how the system handles traffic spikes (e.g., a major weather event drives 50× normal read traffic).

7. Deployment, Cost, and Security

Cover API authentication, secrets management for the upstream credential, cost levers, and any deployment topology decisions.

8. Observability and Failure Handling

Define the key metrics and alerts that let you know you are about to breach the freshness SLA before it actually breaches. Describe graceful degradation when the upstream is slow, partially unavailable, or fully down.

9. Multi-Region Availability and Recovery

What are your RPO and RTO targets? How do active-active or active-passive setups affect ingestion correctness?


What a Strong Answer Looks Like

The data volume here is small enough that storage is almost a non-issue. A strong candidate recognizes this early and focuses their energy on the freshness budget, rate-limit-aware ingestion, idempotency, and degradation behavior. Bring numbers: show the math on your 10-minute budget and your QPS/storage estimates.

Hints

Hint 1

Start by decomposing the 10-minute freshness budget into explicit per-stage allowances (detect, fetch, write, propagate, serve). Every architecture decision should be justified against those numbers.

Hint 2

The provider rate limit (~20 req/s) means fetching all 2,000 stations takes roughly 100 seconds. That alone consumes most of the budget, so figure out that math before designing the ingestion queue.

Hint 3

Idempotency and deduplication are not the same thing. An idempotent write means re-running the same job produces the same DB state; deduplication means you don't re-process the same payload twice. You need both, and a compound primary key like (station_id, observed_at) gives you the former for free.