Chapter 24 · Reading
When is a streaming answer final?
Join horizons, corrections and changelog contracts.
Prerequisites Enrich a stream; When can time move forward? Find chapters in the course contents.
Choose a join boundary and explain append-only output versus updates and retractions.
The situation
An order appears at 10:00. Its payment arrives at 10:07. A dashboard initially calls the order unpaid, then corrects it. Both observations can be reasonable if the output contract allows changing answers.
A join needs a waiting rule
An unbounded stream-stream join can retain unmatched data indefinitely unless a time bound or another completeness rule lets it forget. Define which timestamps determine a match, allowed temporal distance, duplicate multiplicity and the treatment of late matches. Joining “by order ID” alone leaves these questions unanswered.
Suppose payments must have event timestamps within ten minutes after the order. A payment timestamped 10:07 can match the 10:00 order even if it arrives at 10:12, provided event-time progress and the retained-state policy still allow it. Arrival delay and event-time distance are different quantities.
A row can be a revision
An append-only result emits new facts that do not replace earlier ones. An upsert associates a key with a replacement value. A retraction removes a prior contribution, often followed by an insertion of its replacement. A downstream sink must interpret the selected changelog contract.
An early outer-join result may represent an unmatched order, then need correction when a payment arrives. A design that waits until its completeness horizon may emit later and avoid some revisions. Which behavior occurs depends on the actual operator, watermark and late-data rules. Do not promise early unmatched rows for every join implementation.
Worked case
Follow how the consumer replaces the value for order-7. This example assumes the join emits early results.
| Observation | Logical order state | Possible keyed output | Consumer interpretation |
|---|---|---|---|
| Order observed | Payment not yet matched | order-7 → unpaid, if early results enabled | Provisional value |
| Matching payment observed | Paid | order-7 → paid | Replace prior value |
| Completeness horizon passes | No further accepted match under policy | Final for this bounded policy | Very late data needs another path |
Time-varying reference data also needs a rule
A current lookup enriches an event with the table as observed now. A temporal join asks for the version valid at a chosen event time and needs enough version history to answer. Late events, late reference updates and missing versions each require policy.
Before wiring a dashboard, specify its key, correction handling and finality signal. Summing every replacement row as a fresh contribution can double count, just as merging changing task totals can. The contract must extend through the sink, not stop at the join operator.
Think it through
If the sink only appends rows, can it safely consume both the unpaid and paid versions without any other fields?
Show hints
Hint 1
An append sink does not know that one row replaces another.
Hint 2
Think about the key, version and change type needed by a downstream view.
Show explanation
Not as a final-state table. It needs changelog metadata or an upstream conversion to a supported final append-only result. A raw append log can retain both observations, but consumers must reconstruct the intended state using identity and revision rules.
How frameworks implement this
Flink SQL models dynamic tables and changelog streams; sinks must support the query’s required change kinds. Spark Structured Streaming offers output modes and join restrictions that depend on the query and watermark rules. A Kafka topic can carry a changelog, but its messages need a schema and consumer contract.
ReferencesPrimary sources for this chapter’s design case
Use these guides to check the framework or protocol contract discussed in this chapter. Moving “stable” or “current” guides can describe a different release; check the version used by your deployment. These readings do not execute the distributed frameworks they compare.
Flink dynamic tables
Spark Structured Streaming