System Design Atlas

Sensor monitoring with late measurements

07 / 10Worked example

Critical flow

When may ingestion acknowledge a measurement?

The critical sequence connects D-17, BOOT-4, sequence 4711, M-17, W-17 and AL-17. The three scenarios cover normal processing, a duplicate with a late value, and a future device timestamp with a consumer restart.

Starting point Step 6 separates permanent raw log and repeatable projector.

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.

Accept M-17 permanently and finalize W-17 in a controlled manner

Critical Process · Participant, Time and Lasting Effect

Four measurements for W-17 are durably accepted. Only the timer 120 seconds after the window ends finalises it and opens AL-17.

Gateway for D-17
Input
Ingestion log
Projector
Result store
Building team
  1. 01 Gateway for D-17 → InputPUBLISH M-17 · Sequence 4711

    D-17 / BOOT-4, measurement time and reception time

  2. 02 Input · Local processingCheck device key, assignment and time limit
  3. 03 Input → Ingestion logWrite raw event with deduplication key

    Permanent before confirmation

  4. 04 Ingestion log → InputCommit · M-17 accepted
  5. 05 Input → Gateway for D-17PUBACK · Raw-log acceptance confirmed

    Application ingestion is the MQTT receiver here; no evaluation result is promised

  6. Replayable projector reads the durable ingestion log
  7. 06 Ingestion log → ProjectorM-17 and three other different raw events

    29, 30, 31, 32 °C · W-17 [12:00, 12:01) UTC

  8. 07 Projector → Result storeUpdate measurement count and checkpoint atomically

    Event keys prevent double counting

  9. 08 Projector · Local processing12:01 UTC: open → provisional

    Four valid different measurements were projected before 12:03 UTC

  10. 09 Projector · Local processingTrigger processing timers after window end + 120 s

    12:03 UTC · Finalisation takes precedence at the cutoff; timer delay does not extend the deadline

  11. 10 Projector → Result storeAtomically write W-17 final + AL-17 + checkpoint + delivery request

    (29 + 30 + 31 + 32) ÷ 4 = 30.5 °C; rule TEMP-3

  12. 11 Result store → ProjectorResult update committed
  13. 12 Building team → InputGET History and AL-17

    Authorised team API in the ingestion process

  14. 13 Input → Result storeRead final history and alert
  15. 14 Result store → InputW-17 + AL-17 + TEMP-3
  16. 15 Input → Building teamProvide alert with measurement count and rule

    The delivery request is sent separately to the notification service

Result: Acceptance is durable, the domain effect is replayable, and the alert comes only from a final window with sufficient measurements.

  • Gateway and Building Team
  • Ingestion and projector
  • Separate raw log and result store

A final alert, a duplicate with a late value, and a future device timestamp with consumer restart test the same property: processing remains traceable and produces at most one domain effect.

The same participants and messages generate desktop lifelines and the mobile reading sequence. Each scenario defines success, failure timing and its final state.

Three error cases determine the design

Reconnect and Duplicate
The same payload for the same key acknowledges the existing acceptance. Different payloads go into quarantine.
Value after finalisation
The raw value gets late and remains visible. Final mean and AL-17 remain unchanged.
Future time and restart
Quarantine distinguishes device-clock issues from late arrivals. The projector reads its checkpoint and recognises existing result effects.

Terms in this step

At least once
A delivery guarantee that permits duplicates. Exactly-once domain effects require the application's own durable keys and updates.

Try it yourself

In the duplicate case, arrange commit, confirmation and window update. Complete the test after a projector crash.

A hint for your attempt

The confirmation must only follow a permanent raw event; the checkpoint follows with the result effect.

Compare with a possible solution
Acceptance
Input writes raw value and key, then commits and confirms. Test: Crash before commit does not leave a confirmed message.
Duplicate
The same payload finds the existing key. Test: a second PUBLISH increases neither the measurement count nor the alert count.
Restart
The projector crashes after committing W-17, AL-17 and the checkpoint but before the success response. On restart, it loads the result store, finds the final result and reuses its measurement count. Expected: one AL-17, an unchanged final mean and no lost progress.

Apply to your project

What is the first irreversible business effect in your critical process?

Step 8 derives observable bottlenecks and reasons to extend the design from these failure scenarios.