Problem statement
Design the object model and update APIs for a home weather-station hub that ingests readings from several sensors, keeps rolling aggregates, and pushes updates to multiple live displays.
Operating context. One hub gathers measurements from a handful of sensors (outdoor temperature, humidity, barometric pressure, wind, rainfall), each reporting at its own cadence. The hub maintains the latest value and rolling aggregates per measurement (for example, min/max/average over the last hour and last 24 hours). Several displays subscribe to the hub: a current-conditions panel, a statistics panel, and a simple forecast panel that infers a trend from pressure. When a new reading arrives, all interested displays must refresh. Users can toggle display units (metric or imperial). Everything runs in-process on the hub.
Out of scope. Sensor radio protocols and pairing, the cloud upload and public-weather-network endpoints, historical persistence to disk, the rendering/graphics layer of each display, and power management of battery sensors.
What to produce. The class hierarchy (hub, sensor / measurement source, reading, rolling-aggregate store, display subscribers, unit converter), the public API each class exposes, and how updates propagate. Be explicit about: how displays subscribe and receive updates via an Observer relationship so a new display type needs no hub change, how rolling aggregates update in O(1) amortised per reading, and how unit conversion is a pluggable concern applied at the display edge rather than mutating stored readings.
Functional requirements
- Ingest a reading from any sensor, updating the latest value and the rolling aggregates for that measurement.
- Let displays subscribe to and unsubscribe from the hub and receive a notification when relevant data changes.
- Maintain rolling min/max/average per measurement over configured windows (for example, last hour and last day).
- Serve current conditions, the rolling statistics, and a pressure-trend reading to whichever displays request them.
- Convert values between metric and imperial units at the display edge without altering the stored readings.
- Report hub status: connected sensors, each sensor's last-seen time, and the number of active subscribers.
Non-functional requirements
- New sensor types and new display types are added without editing the hub core, via the source and observer interfaces.
- Each reading updates the rolling aggregates in O(1) amortised; a stats query is O(1).
- Notification is thread-safe: concurrent readings and a subscribe/unsubscribe never corrupt the subscriber set or double-notify.
- Unit conversion is a pluggable concern applied at the edge, so stored data has one canonical unit and conversion adds no coupling to the store.
- The design is unit-testable without real sensors or wall-clock time, with sensor sources and clock injected.
- A slow or failing display subscriber does not block ingestion or stall notifications to other subscribers.
Topics
- System Design LLD
- Patterns Observer
- Patterns Strategy
- Oop Solid
- Iot Telemetry