System Design Atlas

Sensor monitoring with late measurements

04 / 10Worked example

Interfaces

What can an acknowledgement of receipt claim?

The gateway sends measurements; the building team reads time series and acknowledges alerts. In the interface example, TEN-17 identifies the tenant assigned to a measurement. Each interface defines its caller, input, result and retry behaviour. This application API design does not specify the MQTT protocol.

Starting point Step 3 established raw logging, time-range queries and replay as separate requirements.

Assumptions for the example case

Example design with 10,000 temperature devices, one value every 10 seconds. An example of a time period ranges from 12:00 to immediately before 12:01. The evaluation will be completed at 12:03 at the earliest. The waiting time of 120 seconds after the end of the time period is an evaluation rule and not a permitted deviation of the instrument clock. Numbers and temperatures are illustrative design assumptions.

Contracts for measurements, history and alerts

Contracts · Ingestion, display and acknowledgement provide separate guarantees

Gateway → Ingestion

AcceptancePOST /telemetry/ingestEntry: TEN-17, D-17, BOOT-4, 4711, measurement time, temperatureResult and repetition: Confirmation after permanent entry log; treat duplicate equally.

Building team → API

CourseGET /devices/D-17/temperaturesEntry: Period and resolutionResult and repetition: Raw values, gaps and final windows; no hidden correction.

Building team → API

ReceiptPOST /alerts/AL-17/acknowledgementEntry: Authorised context, acknowledgement key and noteResult and repetition: open → acknowledged; retries preserve the state; different content for the same key causes a conflict.
  • Callers
  • Own interface
  • Stored status

An ingestion acknowledgement confirms a persisted message. It guarantees neither an exactly-once domain effect nor a temperature alert.

The three contracts distinguish durable acceptance, readable results and human acknowledgement.

The key contracts

  1. POST/telemetry/ingest

    Accept a measurement from D-17.

    Input
    Authenticated gateway; tenant/device are checked against the server-side key allocation, plus bootId, sequence, measurement time and temperature.
    Result
    Acknowledge only after committing the raw log; the same key and payload return the same acceptance result.
    Retry behaviour
    Reconnects may resend a measurement; different payloads for the same key go into quarantine.
  2. GET/devices/D-17/temperatures

    Read time history and data quality.

    Input
    Time period and desired resolution.
    Result
    Raw or aggregated measurements, window status and data gaps.
    Retry behaviour
    Reading query is repeatable; later data remains recognizable as late.
  3. POST/alerts/AL-17/acknowledgement

    Record that the building team has seen the alert.

    Input
    Authorised building team, acknowledgement key and optional note.
    Result
    open → acknowledged. A retry preserves the current state; an alert that is already resolved is not reopened.
    Retry behaviour
    The same key and content return the same acknowledgement; different content for that key returns a conflict.

Separate transport guarantees from domain effects

MQTT QoS
In the sequence example, the application's ingestion component is the MQTT receiver and commits to its durable input log before PUBACK. An upstream broker's PUBACK would acknowledge only the broker's own acceptance; this would require a separate application acknowledgement. POST /telemetry/ingest is the alternative application HTTP adapter with the same acceptance contract.
Durable acceptance
Application ingestion acknowledges only after committing the raw log. Processing, windows and alerts follow asynchronously and can be replayed.
Clock deviation
A separately configured future-time limit compares measurement time with reception time. It comes from device-clock measurements, not the 120-second waiting period. A large positive difference between reception time and measurement time may mean network delay or a slow device clock; device operations needs further clock diagnostics to distinguish them.

Terms in this step

Idempotency
A repetition with the same key and meaning gives the same effect; a conflict remains visible.

Try it yourself

For M-17, describe the input, deduplication key and response. Complete the case of conflict.

A hint for your attempt

The key contains tenant, device, boot session and sequence; measurement time belongs to the payload.

Compare with a possible solution
Acceptance
POST /telemetry/ingest receives TEN-17, D-17, BOOT-4, 4711, measurement time, temperature and authentication. The key is (TEN-17, D-17, BOOT-4, 4711). Respond only after committing the raw log; a crash before commit must leave no acknowledged acceptance.
Retry behaviour
The same payload for the key returns the existing result. Test: resend the message; exactly one raw measurement remains.
Conflict
A different temperature or measurement time for the same key goes into quarantine. Test: a conflict changes no window and creates no alert.

Apply to your project

Where does your contract distinguish acceptance, processing and visible outcome?

The contracts show which facts belong together and which states they lead to.