Detailed Component Design
1. Resilience & Outage Mitigation (Circuit Breaker & Fallbacks)
- Circuit Breaker Pattern: We wrap our external API calls (to NOAA, OpenWeather) with a Circuit Breaker (e.g., Resilience4j). If a vendor experiences an outage or elevated latency, the circuit trips to "open" mode, instantly halting requests to prevent resource exhaustion and cascading failures across our system.
- Stale Cache Graceful Degradation: During a vendor outage, the Weather Service degrades gracefully. Instead of returning a
500 Internal Server Error, it serves a "stale cache" by temporarily extending the Redis TTL for affected Geohashes, ensuring users still see the last known good data. - Queued Retries with Exponential Backoff: When external APIs fail, the Ingestion Service pushes the failed fetch task to a Dead Letter Queue (DLQ) or retry topic. The system will attempt to fetch the data again using exponential backoff until the vendor recovers.
2. Data Accuracy & Freshness
- Multi-Source Consensus: To prevent inaccurate reporting from a single faulty sensor or provider, the Ingestion Service fetches data from multiple authoritative sources.
- Anomaly Detection & Validation: Before raw data enters the main Kafka topic, it passes through a validation layer. If a temperature reading spikes unnaturally (e.g., reporting 150°F in winter), the system flags it as an anomaly, drops the payload, and relies on consensus data from other providers to maintain accuracy.
3. Data Storage & Caching Strategy
- Geohash Caching: Latitude and longitude are converted to Geohashes. Redis stores the current conditions using the Geohash as the key (
weather:{geohash}:current) with a standard 10-minute TTL for freshness. - Time-Series Database (TSDB): Apache Cassandra stores historical data and forecasts. Data is partitioned by Geohash and sorted by timestamp, making range queries highly efficient: to locate the partition and to fetch the time range.
4. Real-Time Alerting Pipeline
- Subscription Management: User alert preferences are stored in a highly consistent relational DB (PostgreSQL).
- Asynchronous Push: When the Stream Processor detects a severe weather event, it publishes to a dedicated Kafka topic. An Alert Worker fans out the payload to APNs/FCM for immediate mobile push delivery.