← All problems
Dashboard
Courses
Problems
Badges
Theme
Sign inStart free
Problem 024 · Caching

Design a Weather API Proxy

Easy 30 min

A weather app with 3 million daily users shows the current conditions and a 7-day forecast for the user's location. The data comes from a third-party provider that charges per call, allows at most 1,000 calls per second and has an outage every few weeks. Design a backend that sits between the app and the provider: it should answer the app quickly, cut provider calls (and the bill) by at least 90%, and keep showing a recent forecast when the provider is down.

Functional requirements

  • Return current conditions and a 7-day forecast for a latitude and longitude
  • Share one provider response between all users in the same area
  • Show the last known forecast, marked with its age, when the provider is unavailable
  • Limit how often a single app install can call the API

Non-functional requirements

  • Responses in under 800 ms at p95, and much faster for popular areas
  • At least 90% fewer provider calls than app requests
  • Forecasts are never more than 15 minutes old while the provider is healthy

Constraints and scale

  • 3 million daily users opening the app about 5 times a day
  • Peak of 800 requests per second on weekday mornings
  • Provider limit of 1,000 calls per second, billed per call

You will practise

  • Design a cache key that groups nearby requests (rounding coordinates to a grid cell)
  • Choose TTLs and stale-while-revalidate behaviour for data that changes slowly
  • Protect a paid, rate-limited dependency from your own traffic
Show 2 hints
  1. Two users 200 metres apart want the same forecast: how could their requests share a cache entry?
  2. Is it better to show a 40-minute-old forecast or an error screen?

Ready to build?

Open the canvas, place your components and explain your decisions. Your draft saves automatically.

Sign in to start

Failure scenarios

  • The weather provider goes down for two hoursThe provider starts returning errors at 07:00 on a Monday, the busiest hour of the week, and recovers at 09:00.

Run them from the workspace once your design is in place.