API Design
Endpoints
POST /v1/subscribe/{city}
- Purpose: Subscribe a user to receive weather notifications for a specific city.
- Request Body:
{
"user_id": "string",
"platform": "ios|android|web",
"notify_level": "ALL|CRISIS_ONLY"
}
- Responses:
201 Created → subscription successful400 Bad Request → invalid input409 Conflict → subscription already exists
GET /v1/weather/{city}/{dayOfTheWeek}
- Purpose: Retrieve weather forecast for a city on a specific day.
- Responses:
{
"city": "London",
"date": "2025-12-08",
"temperature_c": 6,
"humidity_percent": 78,
"precip_probability": 0.6,
"sunny": false,
"hazards": [
{"type": "HIGH_WIND", "level": "SEVERE"}
]
}
- Error Codes:
404 Not Found → city or day not found500 Internal Server Error → service failure
Benefits:
- Makes implementation easier for clients.
- Provides clarity on expected data structures and error handling.
2. Consideration of Edge Cases
- Ambiguous or Conflicting Weather Data
- If multiple providers provide differing forecasts for the same city and day:
- Use weighted averaging for numeric metrics (temperature, humidity, wind).
- For hazard detection, adopt max severity rule (e.g., if one provider reports HIGH_WIND, treat it as urgent).
- Duplicate Alerts
- Each forecast/event has a unique
event_id. - Deduplicate in Redis with TTL to prevent sending multiple notifications for the same event.
- Missed or Delayed Updates
- If a subscriber misses a push (device offline), maintain recent events buffer in Redis (last 24h) to allow delivery upon reconnection.
- High Subscriber Volume in a Hot City
- Shard subscribers to multiple queues to prevent a single queue from becoming a bottleneck.
- Batch notifications to push providers respecting rate limits.