Key takeaways
- ✓Reading a backlog at full speed, our processor got 53.2% of its 1,000 per-ad, per-minute counts exactly right and Quix Streams got 17.5%, and the two disagreed on 526 of the 1,000 counts, with neither matching the batch answer.
- ✓The two processors defined late differently: ours used one watermark for the whole stream, the slowest partition's newest click minus 10 seconds, while Quix's default keeps one per ad, so a click could be late for one ad and on time for another.
- ✓Live, replayed at 10 times real speed, the same processor was 17.5% exact, the same as Quix catching up, and the two totals were one click apart: 292,476 clicks counted by ours and 292,477 by Quix.
- ✓Quix counted 292,477 clicks both live and catching up, because its per-ad clock depends only on each ad's own clicks, in the order they arrive within one partition. Our total moved from 292,476 live to 295,062 catching up.
- ✓Both processors dropped clicks that arrived after their minute was sealed, so both missed clicks against the batch answer: 1.84% of the 300,594 clicks for ours and 2.70% for Quix, when catching up.
- ✓Correcting late clicks instead of dropping them made all 1,000 counts exact, at the cost of 8,118 corrections: results that changed up to 10 minutes after they were first published.
Two processors read the same clicks, from the same Kafka topic, and computed the same thing: clicks per ad per minute, with 10 seconds allowed for late clicks. One was the lab's own processor, written from scratch. The other was Quix Streams, a real Python stream framework. Read as a backlog, at full speed, they disagreed on 526 of the 1,000 counts. Neither matched the batch answer, a DuckDB job that reads the finished stream and gives the reference the lab grades everything against. This chapter takes the disagreement apart: why a backlog exposes it, and what each job means by "late." The examples come from Lab 14 (Stream Processing) of the system design labs, scripts 01_windows_late.py (live and corrections runs), 02_checkpoints.py (kill tests) and 03_framework.py (the two processors, catching up). The stream is 300,594 generated ad clicks, on 100 ads, over 10 minutes, from 49,888 users, replayed into Kafka with 3,170 duplicates and 3% of clicks arriving 1 to 10 minutes late.
The setup is the same laptop as the earlier chapters: an Apple M4 Max with Docker Desktop and 16 virtual CPUs. Each configuration is one recorded run. The machine was busy (load averages of about 7 to 12), so read the shapes more than the last digit. The second half of the video covers two counting sketches, Count-Min and HyperLogLog, which are not part of this chapter.
Why a backlog splits two processors
Kafka splits a topic into partitions: ordered slices that are read in parallel. The lab's topic has six. The replay keys each click by its ad, so all of one ad's clicks land in the same partition, in order.
Every stream job needs a watermark: its claim that "I have probably seen everything before time T." A window (here, one minute for one ad) is sealed, its count emitted, when the watermark passes the window's end. A click that arrives after its window is sealed is late. A late click is dropped, or, with corrections, added later.
Where the two processors differ is the watermark:
- Ours keeps one watermark for the whole stream: the newest click in the slowest partition, minus the 10-second delay. No window can be sealed until the slowest partition has moved past it.
- Quix Streams, by default, keeps one per key, here per ad: that ad's newest click, minus its 10-second grace period. Each ad's clock moves at its own pace.
While clicks arrive live, in step, the two clocks move together, and the two jobs nearly agree. A backlog breaks that. When the partitions are read as fast as the machine allows, one partition can run ahead of another. Ours then waits for the slowest partition before it seals anything, so more clicks arrive while their minute is still open and count. Quix's clock for an ad depends only on that ad's own clicks, so how fast the partitions are read does not change it.
The lab did not record each partition's read position, so the reason the slow partition held our clock back is the most likely explanation, not a measured one.
The workflow and the recorded results
The lab ran each configuration against the same replay:
- Catching up (
03_framework.py). The full stream was put into Kafka first. Then our processor (delay 10 seconds, no checkpoints) and Quix Streams (grace 10 seconds, exactly-once, and at-least-once as a second run) each read the whole topic as fast as they could. Each answer was graded cell by cell against batch. - Live (
01_windows_late.py). The stream was replayed at 10 times real speed, and our processor with the same 10-second delay read it as it arrived. The lab labels this run "event time, delay 10 s." - Live Quix (
02_checkpoints.py). A Quix Streams run that was not killed. The kill test compares a killed Quix run with this one, not with batch, so its exactness against batch was not measured in that script.
The results, for the grid of 1,000 counts (100 ads by 10 minutes):
| Run | Job | Cells exactly right | Clicks not counted | Clicks counted |
|---|---|---|---|---|
| Catching up | Ours | 53.2% (532) | 1.84% (5,532 late clicks dropped) | 295,062 |
| Catching up | Quix Streams, exactly-once | 17.5% (175) | 2.70% | 292,477 |
| Catching up | Quix Streams, at-least-once | 17.5% (175) | 2.70% | 292,477 |
| Live, 10 s delay | Ours | 17.5% (175) | 2.70% (8,118 dropped) | 292,476 |
| Live | Quix Streams | not measured against batch | 2.70% | 292,477 |
Catching up, the two jobs disagreed on 526 of the 1,000 cells. Exactly-once and at-least-once (a restart may repeat work, but never skips it) gave the same answer for Quix, because nothing crashed in this run.
Ours was the more accurate of the two catching up, because it dropped 5,532 late clicks, while Quix missed 8,117 clicks. Live, it dropped 8,118 and was 17.5% exact, the same as Quix catching up. The same processor, on the same stream, scored 53.2% or 17.5% depending on how quickly it read.
Both read the whole topic in Kafka as fast as they could, after an outage (03_framework.py).
Readouts
Live, the two totals were 1 click apart (292,476 and 292,477). Catching up, the two jobs disagreed on 526 of 1,000 cells. Quix counted 292,477 both ways.
Quix's behaviour is the reverse. Its total was 292,477 clicks in every run, catching up and live. Its exactly-once mode (each click counted once, even across restarts) also survived 20 kills with the same total as an uninterrupted run, so the difference between the two processors is the definition of late, not crash handling.
What the delay buys
The delay sets how long a window waits for late clicks. In the live runs, ours dropped 9,520 clicks with no delay, 8,118 with 10 seconds and 6,784 with 60 seconds. Going from 10 to 60 seconds cut the drops by only about 16% and made every result about 50 seconds later. This stream's lateness has two humps: most clicks arrive within 5 seconds, and the 3% that are late are 1 to 10 minutes late, so no delay short of 10 minutes catches them. The lab's guidance is to choose the delay from the measured lateness, not by feel.
Corrections avoid the choice. The corrections run, with the same 10-second delay, made all 1,000 counts exact, at the cost of 8,118 corrections, one for each click that arrived after its minute had been published. A result for a minute could change up to 10 minutes after it first appeared, so any consumer of the counts has to replace a result by its window, not append it.
Caveats
- One run per configuration. Each row is a single recorded run on one laptop. The live and catching-up runs used different runs of the replay, so compare shapes, not last digits.
- The live runs shared a replay. Six copies of our processor read the same live replay with different settings, so the live figures come from a concurrent setup, not a lone job.
- Quix's live exactness was not measured. Its 292,477 counted clicks are recorded, and the share of clicks missing follows from that count, but its cell-by-cell match against batch was not run live.
- Quix's dropped count was not recorded in the catching-up run. The 8,117 missing clicks come from its error total.
- The explanation is a likely one. The uneven read speed of the partitions was not measured. The video says "most likely," and so does this chapter.
- Not covered: speed (ours read the topic in 2.7 seconds and Quix in 12.0, but that is not what this chapter is about), the checkpoint kill test beyond the one Quix run, Count-Min and HyperLogLog, and any real cluster or production load.
The checklist
- Write down what "late" means before the job runs: the delay, and whether the clock is per stream or per key.
- Keep a batch answer and grade the stream against it, cell by cell, not by its total.
- Compare a live run with a catch-up run of the same stream. If the totals differ, the job depends on timing.
- Prefer per-key clocks or corrections when results must be reproducible. Corrections gave 100% exact cells here.
- Check which watermark a framework uses before comparing its numbers with another system's.
Quiz
1.Catching up, our processor and Quix Streams disagreed on 526 of 1,000 per-ad, per-minute counts, though both ran the same job. What is the most likely reason?
2.Live, our processor counted 292,476 clicks; catching up, it counted 295,062. Why did its total change, when Quix's did not?
3.The lab made every count exact by correcting late clicks instead of dropping them. What does that cost?
Check your understanding
Try each question before opening its answer.
Ours counted 295,062 clicks catching up and 292,476 live. Why did its total change with how it read, while Quix's did not?
Ours uses one watermark for the whole stream: the newest click in the slowest partition, minus 10 seconds. Read unevenly, that partition lags, the clock lags with it, and more clicks count as on time. Quix's clock is one per ad and depends only on that ad's clicks, in order, so the reading speed does not change it. The lab did not record partition positions, so this is the most likely cause, not a measured one.
Neither job matched batch. Why keep batch as the reference, and what did it show?
Batch reads the finished stream and gives the answer that has every click, so it is the only way to see how many clicks each job missed. Comparing the two jobs with each other shows only that they differ. Batch shows the shortfall: catching up, ours missed 1.84% of the 300,594 clicks, and Quix missed 2.70%.
Quix's exactly-once mode is meant for crashes. Did it change which clicks count as late?
No. In the kill test, Quix's exactly-once run survived 20 kills with the same count as an uninterrupted run: 292,477 clicks and 1,000 of 1,000 cells. Exactly-once keeps each click counted once across restarts. It does not change Quix's per-ad clock, so it cannot change which clicks are late.
The lab reports 53.2% for our processor. What should you check before quoting that as its accuracy?
That it is one catching-up run on one laptop, against one batch answer. The same processor, on the same stream, scored 17.5% live, so its accuracy depends on how fast it read. Quote the live and catching-up figures together, and say which one you measured.
Next up: Chapter 34, polling, server-sent events and WebSockets. This chapter's stream jobs wrote counts that a dashboard reads. The next one covers the other half: pushing each update to many connected users as it happens, and the two classic ways to fan it out.