EasyStarter

Weather Dashboard API

CachingAPI DesignDatabases

Problem Statement

SkyCheck is building a weather API service that developers use to get current weather and 5-day forecasts. The service:

- Aggregates sources - fetches data from 3 upstream weather providers (OpenWeather, WeatherAPI, AccuWeather) and merges/averages the results for better accuracy.Caching - weather data doesn't change every second. Cache results per location for 10 minutes to reduce upstream API calls and cost.Location support - accept queries by city name, zip code, or lat/long coordinates. Auto-detect user location via IP if not specified.Rate limiting - starter tier: 100 calls/hour; pro tier: 10,000 calls/hour per API key.Historical data - store and serve the last 30 days of weather data per location.

Expected usage: 500,000 API calls per day across 10,000 API keys.

What You'll Learn

Design a weather API that aggregates data from multiple providers, caches results, and serves forecasts. Build this architecture under realistic production constraints, then validate tradeoffs in the design lab simulation.

CachingAPI DesignDatabases

Constraints

API calls/day~500,000
Active API keys~10,000
Cache TTL10 minutes
Response time< 200 ms (cached) / < 2 s (uncached)
Locations tracked~50,000
Availability target99.9%
ApproachClick to expand

Interview-Ready Approach

1) Clarify Scope and SLOs

  • Problem statement: Design a weather API that aggregates data from multiple providers, caches results, and serves forecasts.
  • Design for a peak load target around 100 RPS (including burst headroom).
  • API calls/day: ~500,000
  • Active API keys: ~10,000
  • Cache TTL: 10 minutes
  • Response time: < 200 ms (cached) / < 2 s (uncached)
  • Locations tracked: ~50,000

2) Capacity Planning Method

  • Convert traffic and growth constraints into request rate, storage growth, and concurrency budgets.
  • Keep at least 2-3x safety margin per tier (ingress, compute, storage, async workers).
  • Reserve explicit latency budgets per hop so p95 can be defended in review.

3) Architecture Decisions

  • Caching: Put cache on hot read paths first and pick cache-aside or write-through explicitly.
  • API Design: Standardize API boundaries, idempotency keys, pagination, and error contracts first.
  • Databases: Define a clear system-of-record and design read/write paths separately before adding optimizations.

4) Reliability and Failure Strategy

  • Bound staleness with TTL + invalidation hooks for critical entities.
  • Apply strict input validation and backward-compatible versioning.
  • Use strong write constraints (transactions or conditional writes) and explicit backup/restore strategy.

5) Validation Plan

  • Run one peak-load test, one dependency-degradation test, and one failover test.
  • Verify idempotency for all retried writes and async consumers.
  • Track user-facing SLOs first: p95 latency, error rate, and successful throughput.

6) Trade-offs to Call Out in Interviews

  • Caching: Higher hit rate cuts latency/cost, but stale data and invalidation bugs become primary risks.
  • API Design: Rich APIs improve developer speed but can create long-term compatibility burden.
  • Databases: SQL gives stronger transactional guarantees; NoSQL often gives better write scaling and flexibility.

Practical Notes

  • Cache weather data in Redis keyed by a normalized location identifier (e.g., geohash at precision 5).
  • Use a circuit breaker for upstream provider calls - if one is down, fall back to the others.
  • Rate limiting: use a sliding window counter in Redis per API key.

Learn the Concept

Practice Next

Reference SolutionClick to reveal

Why This Solution Works

Request path: The solution keeps ingress, service logic, and stateful dependencies separated so each layer can scale independently.

Reference flow: Web Clients -> API Gateway -> API Service -> Primary SQL DB -> Redis Cache

Design strengths

  • Cache sits on the read path to absorb repeated queries and keep DB pressure stable.

Interview defense

  • This design makes bottlenecks explicit (ingress, core compute, persistence, async workers).
  • It supports progressive scaling without re-architecting the core request path.
  • It keeps correctness-sensitive state changes in durable systems while offloading background work asynchronously.