2 Stream Processing Fundamentals
More
Depth: Practitioner
Progress saves as you read. Mark sections complete as you go; your progress appears in the sidebar.
-
How can the shipment react before this event becomes old?
2.1 Start With One Event That Cannot Wait
This section: Start With One Event That Cannot Wait — Imagine a temperature event from a cold-chain sensor arriving while the shipment is still moving.
Imagine a temperature event from a cold-chain sensor arriving while the shipment is still moving. The useful question is not just “what was the reading?” It is whether this event belongs to the right time, window, and state before anyone acts on it.
Stream processing starts there: one live event, a clock, a window rule, and a review record that explains what the system did. Once that path is visible, terms like watermark, late event, checkpoint, and recovery become tools for making the decision repeatable.
2.2 Streams Are Data In Motion
This section: Streams Are Data In Motion — Stream processing handles events while new events are still arriving.
Stream processing handles events while new events are still arriving. In IoT, that matters when a reading should change a live status, alert, control review, anomaly review, or downstream record before a complete historical dataset exists.
The fundamentals are not tied to a single tool. A reviewable stream design states the event source, the timestamp that controls the calculation, the window that bounds the question, the rule for late or duplicated events, the state that must be remembered, and the evidence that should trigger retest.
Worked example: a freezer sensor sends one temperature reading per minute, but the device buffers data during a cellular outage. When connectivity returns, five older readings may arrive after newer readings. A stream that answers "was the package above 8 C for 15 minutes?" should use event time, not arrival time, because the question is about when the package was warm. The record also needs the allowed-late rule so reviewers know whether a delayed reading can revise the result.
The same stream can produce more than one output. A live dashboard may show the latest received value, while a compliance window uses event-time readings and correction markers. Both are valid if their contracts are explicit; the pitfall is letting the dashboard's freshness silently define the durable record.
If you only need the intuition, this layer is enough: use streams when current events change the decision; use event time when the real-world observation time matters; use windows to make an endless flow answerable; and keep late-event, state, and recovery rules explicit.
Core Ideas
Event stream
An ongoing sequence of sensor readings, device events, commands, alerts, or upstream messages.
Event time
The time the observation happened, which may differ from when the platform received or processed it.
Window
A bounded interval, moving range, session, or sequence that turns an unbounded stream into a computable question.
State and recovery
The counts, aggregates, joins, sessions, output markers, and checkpoints needed to resume and explain results.
Beginner Examples
Sort these examples by the decision's useful delay, not by the number of events. The freezer alert benefits from current evidence, whereas a monthly summary can wait; the delayed reading and live dashboard examples then show why timing and presentation still need durable rules.
A live freezer alert usually belongs on the stream path because its action value falls if it waits for a daily report. A monthly energy summary can remain a batch result when no consumer acts on partial totals. That contrast makes the consumer's useful delay—not event volume—the first design test.
Timing semantics come next. Evaluate a delayed sensor reading with its event-time and late-event rule instead of discarding it solely because it arrived after newer records. A dashboard may show the latest received value quickly, but the durable stream record must still identify later corrections. These examples connect the decision for streaming to the evidence needed when arrival order and display order diverge.
Event time and processing time narrated tour
Play silently with captions on provisional storyboard timing; narration audio is pending. Production pacing is independent of model time. Choose Reduced motion for a complete still at each beat.
Play the tour to open the workbench. Pause, replay a beat, or read the full transcript below. Situations the model cannot show use captions only and keep the existing frame.
Full transcript — Event time and processing time (8 beats)
B1 — Buffered factory reading
You are the engineer keeping a factory's sensor status useful when a buffered reading arrives late. Before someone acts on that status, the reading needs to belong to the time it describes. Receiving it now does not mean the sensor measured it now.
Model caption: Factory sensor status depends on when a reading was measured, even when it arrives later.
B2 — Measurement and receipt
Event time means when the sensor measured. Processing time, in our model, means when the processor received the reading. A window groups readings into a time interval. When the question concerns when a condition happened, event time determines which window gets the reading.
Model caption: Event time: measurement. Processing time: receipt. Event-time windows group readings by measurement time.
B3 — Watermark and lateness
A watermark estimates how far event time has progressed, helping the processor decide when results can close. Allowed lateness gives a window extra time to accept older readings. Together, those settings determine whether a delayed reading can still change its window's result.
Model caption: A watermark estimates event-time progress. Allowed lateness permits older readings to update a window for a limited time.
B4 — Seven second arrival lag
Take the factory's buffered reading. Its event time is three point two seconds, and its processing time is ten point two seconds. Subtract three point two from ten point two: the reading waited seven seconds. It still describes the earlier moment, even though newer measurements arrived first.
Model caption: E: measured at 3.2 s; received at 10.2 s. Arrival lag: 10.2 − 3.2 = 7 s.
B5 — Assign the earlier window
Use five second windows. Divide three point two by five to get zero point six four. Round down to zero, then multiply by five: the window starts at zero. Add five: it ends at five seconds, excluding five itself. The delayed reading belongs in that earlier window.
Model caption: 3.2 ÷ 5 = 0.64; round down to 0; 0 × 5 = 0; 0 + 5 = 5. E belongs in [0, 5) s.
B6 — Late accepted reading
Before it arrives, the greatest event time received is eight seconds. Subtract the two second watermark delay to get six. Keep the larger of zero and six: the watermark is six seconds. Add three seconds of allowed lateness to the window's five second end: eight. Six has not passed eight, so the reading is accepted late. That window now contains four accepted readings.
Model caption: Watermark: max(0, 8 − 2) = 6 s. Grace limit: 5 + 3 = 8 s. E is late accepted; [0, 5) s contains four accepted readings.
B7 — Older than the watermark
The misconception is that every reading older than the watermark must be left out. Our reading's three point two seconds is older than six, but its window still allows an update. The watermark has passed the window's end, while the extra allowance keeps the result open to correction.
Model caption: Older than the watermark does not automatically mean excluded: 3.2 < 6, and 6 is still within the window's 8 s grace limit.
B8 — Delay and window closure
A longer watermark delay means waiting longer to close windows and keeping more state, the information held for those calculations. For your factory, the trade is speed against room for delayed readings. Let measurement time choose the window, and let the lateness rule decide whether it can still change.
Model caption: More delay keeps the window open longer. Let measurement time choose the window, and let the lateness rule decide whether it can still change.
Overview Knowledge Check
2.3 Build The Stream Review Record
This section: Build The Stream Review Record — A practical stream-processing review should produce a small record that another engineer can test against representative events.
A practical stream-processing review should produce a small record that another engineer can test against representative events. The record should explain why the stream is needed, what the output means, how events are grouped, what happens when events are late or duplicated, and which assumption reopens the decision.
This keeps the design from becoming a tool-first claim such as "we use a streaming platform, so the result is real time." The useful proof is narrower: given this source trace and this rule set, the processor emits this result, handles this degraded case, and can recover its state without changing the meaning of the output.
Review Sequence
Use one consumer decision to hold the sequence together. Each step narrows the same claim: why events must be processed now, what those events mean, how the question is bounded, and which state and correction evidence supports the output.
Name the consumer decision first: who acts, what changes, and how quickly the result loses value. Then classify the source events by recording their meaning, required fields, timestamp basis, and validation behavior. Those two steps stop a convenient transport or processor from defining the analytical question.
Turn the endless flow into a bounded question with a tumbling, sliding, session, or sequence rule that matches the consumer's need. Define whether late or corrected events revise the result, mark it provisional, enter review, or remain outside the decision. Finally, record the maintained state, checkpoint expectation, emitted output, correction behavior, and retest triggers. The resulting sequence links the original action need to evidence that can survive replay and review.
Evidence Ledger
Worked Review: Delayed Sensor Events
Suppose a condition-monitoring stream computes a five-minute vibration status for each motor. One reading arrives after newer readings from the same motor, but its event-time timestamp is trustworthy.
The review does not start by asking which product should process the stream. It starts by checking the event-time rule, window type, allowed lateness, duplicate policy, state key, and consumer tolerance for correction. If the rule allows updates, the affected window is corrected and the output contract tells consumers that the status changed. If the rule does not allow updates, the late reading is still recorded according to policy so the team can review whether the lateness assumption is still valid.
Practitioner Knowledge Check
2.4 Time Progress, State, And Recovery
This section: Time Progress, State, And Recovery — Under the hood, a stream processor turns an unbounded flow into state transitions.
Under the hood, a stream processor turns an unbounded flow into state transitions. Each accepted event is parsed, assigned to a key or grouping rule, placed against a timestamp basis, applied to maintained state, and then used to emit or revise an output when the policy says enough evidence exists.
Watermarks and checkpoints support that process, but they do not replace the stream contract. A watermark is a processor's estimate that event time has advanced far enough to close or publish a result. A checkpoint is recovery evidence for maintained state. Neither proves that the chosen window, timestamp, or late-event rule is semantically correct for the consumer.
Worked example: a motor stream keeps a five-minute rolling count of over-vibration events by asset id. The processor state includes the asset key, the active window, the current count, and whether the emitted status is provisional or final. A checkpoint can restore that count after restart, but the restored bytes are only meaningful if the same event-time rule, duplicate policy, and output contract are still in force.
To test recovery, replay a short trace through a restart: one on-time reading, one duplicate retry, one late reading, and one malformed payload. The expected result should say which events changed state, which were rejected, whether an output was revised, and which checkpoint or replay marker proves the restart did not duplicate the output.
Also record what the consumer sees after recovery. If the status is recalculated from the same events, the output should keep the same identity and show a recovery note, not create a second alert. If a late event changes the count, the output should identify the revised window and the event that caused the correction.
Internal Responsibilities
Validation boundary
Malformed, missing, impossible, or unknown-version events should be rejected, quarantined, or normalized before they change stream state.
State key
The key controls which events share counts, aggregates, sessions, joins, or pattern history.
Watermark policy
The policy defines when a result can be emitted and what happens to events that arrive after that point.
Recovery evidence
Checkpoints, replay behavior, deduplication rules, and output markers explain how a restart avoids losing or duplicating meaning.
Failure Modes To Review
Exercise these failures with a short trace rather than discussing them abstractly. Include an offline-buffered reading, a duplicate retry, and a restart so the review can distinguish timestamp error, identity error, state recovery, and output ambiguity.
Start the trace with clock drift: an event can be syntactically valid while its event-time value is inconsistent. Add offline buffering so receive order differs from observation order after reconnection, then replay a duplicate with the same stable identity. These cases separate timestamp validation, ordering policy, and deduplication rather than hiding all three behind “late data.”
Continue long enough to expose state growth in sessions, joins, or wide windows, and inspect whether retention and cleanup match the contract. Then examine the consumer output. If a provisional result is displayed as final or a correction has no visible identity, the processor may be operational while the decision remains ambiguous. The review is complete only when each failure produces an expected state transition and an explainable output.
Retest Signals
Retest the stream when a source timestamp changes meaning, a firmware release changes event shape, offline buffering patterns shift, state retention changes, checkpoint or replay behavior changes, a consumer stops accepting corrections, or an output moves from advisory review to automatic action.
Under-The-Hood Knowledge Check
2.5 Summary
This section: Summary — Stream-processing fundamentals make data in motion reviewable.
Stream-processing fundamentals make data in motion reviewable. The core decisions are whether the consumer truly needs current events, which timestamp defines the event, which window or sequence makes the question finite, how late or duplicate events behave, what state must be maintained, and what evidence proves recovery and retest behavior.
Good stream designs keep these contracts visible. They avoid hiding semantic decisions behind tool names, fast dashboards, or operational checkpoints that do not explain what the result means.
2.6 Key Takeaway
This section: Key Takeaway
Use stream processing when decisions depend on events in motion, then make event time, windowing, late-event behavior, state, recovery, and retest evidence explicit.
2.7 See Also
This section: See Also
Stream Processing Architectures
Compare architectural patterns that implement event-time, state, and output contracts.
Building IoT Streaming Pipelines
Apply stream fundamentals across ingestion, processing, quality gates, and downstream handoffs.
Common Pitfalls and Worked Examples
Review late data, duplicate events, pressure, schema drift, recovery, and consumer-contract failures.
Basic Stream Processing Lab
Practice turning event traces, timing rules, windows, and outputs into a small review record.
Find help
3 reviewed answers.
Where should I start in a module?
Open the module page from the sidebar to see its chapters in order. Use the module map to return to a topic you need.
Modules and pathsReviewed
What can I try when a project does not work?
Check the symptom, then work through the diagnostic steps. Keep the error message and the smallest example that reproduces it.
When you are stuckReviewed
How do interactive examples work?
Use the interactive guide to check how examples and simulations work before changing your project.
Interactive examples guideReviewed
