Design a System to Ingest Periodic Weather Data from Multiple Sub-Stations

Difficulty: MEDIUMCategory: HLDFrequency: 1Asked On 2022-06-10

Problem Statement

Designing a scalable and reliable data ingestion system that collects periodic weather readings (e.g., temperature, humidity, wind speed, rainfall) from thousands of weather sub-stations deployed across different geographies. The ingested data will be stored, processed, and made available for analytics, dashboards, and alerting systems.


✅ Functional Requirements


1.<span></span>Data Ingestion
2.<span></span>Accept periodic data pushes (e.g., every 5 minutes) from weather sub-stations.
3.<span></span>Support multiple protocols (HTTP, MQTT, gRPC, etc.).
4.<span></span>Handle idempotent writes (avoid duplicates in case of retries).
5.<span></span>Data Storage
6.<span></span>Store raw data for historical analysis.
7.<span></span>Support time-series queries (latest values, hourly/daily aggregates).
8.<span></span>Enable efficient retrieval by station ID + timestamp.
9.<span></span>Processing
10.<span></span>Real-time aggregation (e.g., average temperature per region every 15 minutes).
11.<span></span>Trigger alerts if data crosses thresholds (e.g., rainfall > 100mm/hr).
12.<span></span>APIs & Access
13.<span></span>Provide APIs for dashboards, analytics pipelines, and external clients.
14.<span></span>Support both real-time queries and historical analysis.


⚙️ Non-Functional Requirements


1.<span></span>Scalability → Support millions of records per day across thousands of sub-stations.
2.<span></span>Fault Tolerance → Handle network drops or delayed station data.
3.<span></span>Low Latency → Ingest data within a few seconds of arrival.
4.<span></span>Durability → Data must not be lost, even on node failures.
5.<span></span>Extensibility → Easy to add new sensors or new weather metrics.


🔐 Constraints & Assumptions


1.<span></span>Each sub-station sends data periodically (fixed or variable intervals).
2.<span></span>Payload size is small (KB range) but frequency is high.
3.<span></span>Data may arrive late or out-of-order due to connectivity issues.
4.<span></span>System should be cloud-deployable and support horizontal scaling.


🧱 Key Components to Design


1.<span></span>Ingestion Layer → API Gateway or Kafka for receiving weather data streams.
2.<span></span>Buffer/Queue → Kafka / Pulsar to handle bursty data and retries.
3.<span></span>Processing Layer → Stream processing (Apache Spark, Flink, or Storm) for cleaning, deduplication, and aggregation.
4.<span></span>Storage
5.<span></span>Hot Data: Time-series DB (e.g., InfluxDB, TimescaleDB) for recent queries.
6.<span></span>Cold Data: Data lake (S3, HDFS) for historical analysis.
7.<span></span>Serving Layer → REST/gRPC APIs, dashboards, alerting service.
8.<span></span>Monitoring & Alerts → Track ingestion lag, dropped stations, and processing errors.


📈 SLAs & Success Metrics


1.<span></span>Availability: 99.9% uptime for ingestion endpoints.
2.<span></span>Latency: <5s end-to-end ingestion to storage pipeline.
3.<span></span>Scalability: Support at least 10,000 stations sending data every minute.
4.<span></span>Durability: No more than 0.001% data loss.


🔄 Trade-offs to Discuss


1.<span></span>Batch vs. stream ingestion.
2.<span></span>SQL DB vs. Time-series DB for storage.
3.<span></span>Strong consistency vs. eventual consistency in data arrival.
4.<span></span>Cloud-native (serverless ingestion with Kinesis, Pub/Sub) vs. self-managed Kafka/Spark.


👉 The interviewer will expect you to:


1.<span></span>Draw the pipeline diagram (Sub-stations → Ingestion → Queue → Processing → Storage → API/Analytics).
2.<span></span>Discuss how you handle out-of-order or missing data.
3.<span></span>Justify storage choices (time-series DB vs OLAP DB).
4.<span></span>Talk about scale estimation (events/sec, storage per year).


Solution

Comments