Data engineering·topic 2 of 8
Time and correctness in streams
Batch has one clock. A stream has two, and almost every confusing streaming bug is the gap between them: the moment something happened and the moment your code found out. These are the words for that gap and for what you are allowed to do while you wait.
Read in order · tick what you already know
- 01
the phone was in a tunnel, so the tap happened at 14:02 and your job saw it at 16:40, and the hourly chart has to put it at 14:00.
Event time
- 02
you restarted the job to fix a bug and every bucket moved, because the buckets were made from when the job read the record.
Processing time
- 03
the record has no usable timestamp of its own, so you stamp it as it enters the log and everything downstream agrees on that.
Ingestion time
- 04
the update arrived before the insert, and your naive consumer wrote a row it then couldn't find a parent for.
Out-of-order events
- 05
the job announces that it believes nothing older than 14:30 is still coming, and closes every window that ended before then.
Watermark
- 06
yesterday's total went up this morning, because eight hundred events from a phone that was offline finally arrived.
Late-arriving data
- 07
the window emitted a result at 15:00 and keeps updating it for another two hours before it finally throws the state away.
Allowed lateness
- 08
the dashboard shows a partial count that keeps rising, because the window emits early every ten seconds before it finally closes.
Window trigger
- 09
every event lands in exactly one five-minute bucket and the buckets sit end to end with no gaps.
Tumbling window
- 10
you want 'five errors in any sixty seconds', so every event is counted in twelve overlapping windows at once.
Sliding window
- 11
the window has no fixed length; it just stays open until the user does nothing for thirty minutes, and then it closes.
Session window
- 12
one quiet partition sent nothing for an hour and the whole job's watermark froze, so no window closed anywhere.
Idle partition stall
- 13
the job is holding four hundred gigabytes of per-user counters, and 'just restart it' stopped being free some time ago.
Stateful stream processing
- 14
the running total is kept per customer id, so scaling out just moves whole customers between workers.
Keyed state
- 15
the operator's state is an embedded key-value store on local disk, and losing that disk means restoring from remote storage before anything can run.
State backend
- 16
the job died and came back at the position it had saved ninety seconds ago, replaying everything since without duplicating output.
Pipeline checkpoint
- 17
you needed to deploy a new version of the job, so you took a snapshot deliberately, stopped it, and started the new code from that snapshot.
Savepoint
- 18
the job crashed mid-window, replayed the last two minutes, and the output table still shows each event counted exactly one time.
End-to-end exactly-once
- 19
the writes are staged and only made visible when the checkpoint commits, so a crash halfway leaves nothing half-written.
Transactional sink
- 20
you keep the ids you have seen for the last twenty-four hours and drop repeats, and a duplicate that arrives twenty-five hours later gets through.
Deduplication window
- 21
you need the click matched to the impression, and one of them is always five minutes behind the other.
Streaming join
- 22
you priced the order using the exchange rate as it was at the moment of the order, not the rate as it is now.
Temporal join
- 23
the same topic can be read as a log of every change or collapsed into a table of current values, and which one you want depends on the question.
Stream-table duality
- 24
there are two implementations of the same metric, one fast and approximate and one slow and correct, and they disagree by two percent.
Lambda architecture
- 25
there is one streaming job, and correcting history means replaying the log through it rather than running a different batch job.
Kappa architecture