Unit 8 of 15 · about 4 hours · explain, derive
Event time versus processing time and tumbling, sliding and session windows
Windows turn an unbounded stream into finite pieces, and the clock behind them decides what each piece means. A redeploy that replays a backlog must not rewrite the measured history.
You'll be able to
- Explain event time versus processing time and the artifacts that processing-time windowing invents during backlogs.
- Derive window membership for tumbling, hopping, sliding and session windows on a fixed event sequence.
- State the per-window output rule, including empty windows and the session-gap boundary.
Covers
Read
In this order, only the parts listed
0 of 3 done
- What, where, when and howThe Dataflow Model (Akidau et al., 2015)
Section 2: the what, where, when and how questions; event time versus processing time; windows, triggers and accumulation with discard, accumulate and retract modes
- Reasoning about time and window typesDDIA 2e - Chapters 11 to 13 Batch and Stream Processing
Chapter 12, Reasoning About Time through Types of windows (pp. 518 to 522): event versus processing time, the backlog rate-spike artifact, tumbling, hopping, sliding and session windows with their state costs
- Timely stream processing: notions of time and windowingApache Flink 2.3 - Event Time, State and Checkpointing
Notions of Time: Event Time and Processing Time; Event Time and Watermarks; Lateness; Windowing (tumbling, sliding, session and time versus data driven windows)
Focus on
- Event time comes from the event and never changes; processing time comes from the machine clock. Measuring a replayed backlog by processing time invents a spike the real request rate never had.
- Tumbling assigns each event to exactly one fixed window. Hopping overlaps fixed windows. Sliding holds events that occur within an interval of each other, even across fixed boundaries. Session groups one user's events until an inactivity gap ends the session.
- Two events five minutes apart can share a five-minute sliding window while falling in different tumbling windows. Fixed boundaries and pairwise intervals answer different questions.
- Window state cost follows the buffering need: counters stay constant size, while sliding windows and joins buffer events until the window closes.
Common mistakes · 3
- Windowing by arrival time and calling it event time. Reprocessing history then answers a different question than live processing did.
- Assuming hopping equals sliding. Hopping has fixed boundaries; sliding is defined by pairwise intervals.
- Leaving the session-gap boundary unstated. Record whether a gap equal to the threshold starts a new session, since systems differ.
Try it yourself
Closed-book, before checking anything
Quiz yourself
Answer first, then mark it. Missed ones go to Review.
0 got · 0 missed
1.A redeployed processor burns through a one-minute backlog and the per-second request chart spikes. What caused it, and what is the fix?Answer
The chart is windowed by processing time, so the backlog compressed into seconds of processing. Window by event time to recover the steady real rate.
2.Two events occur at 10:03:39 and 10:08:12. Which windows do they share: five-minute tumbling, five-minute hopping with a one-minute hop, five-minute sliding, or sessions with a 30-minute gap?Answer
The sliding window and the session. They are 4 minutes 33 seconds apart, so some five-minute interval holds both, and the gap is far below 30 minutes. Tumbling windows put them in 10:00 to 10:05 and 10:05 to 10:10. The last one-minute hop holding 10:03:39 is 10:03 to 10:08, which ends before 10:08:12; a 30-second hop would give 10:03:30 to 10:08:30, which holds both.
3.Events for users
[a, a, b, a, b]arrive at[0, 4, 5, 10, 11]with inactivity gap 6, starting a new session when the gap reaches the threshold. What are the session numbers?Answer[1, 1, 1, 2, 2]. User a continues at gap 4 and restarts at gap 6; user b starts at 5 and restarts at gap 6. Each user is tracked independently.4.Events at timestamps 2 and 12 carry values 10 and 5 with window size 5, windows starting at 0. What does the tumbling aggregation return?Answer
[10, 0, 5]. Window index is integer division , so the events land in windows 0 and 2, and the empty window 1 reports 0.
Practice
- AlgoMaster: Aggregate Tumbling Windows
Sum values per window index from 0 through the highest touched window, with 0 for empty windows; timestamps need not be sorted
The judge tests the assignment function only, on a subscription the learner owns. Watermarking, lateness and state recovery are mini-project work.
- AlgoMaster: Assign Events to Session Windows
Per-user sessions with the gap-reaches-threshold rule; interleaved users stay independent
Same scope as above: assignment logic here, event-time execution and recovery in the mini-project.
You're done when
You can bucket any timestamp by hand under each window type and predict what a backlog replay does to processing-time charts.
Only when you can do this without notes.
Leads to
Notes
Resources · 3 for this unit, 15 more in the section
- DDIA 2e - Chapters 11 to 13 Batch and Stream ProcessingMartin Kleppmann and Chris Riccomini · primary
Read batch processing, stream processing and the streaming-systems philosophy in order. For every guarantee, mark the source position, operator state, output effect and recovery boundary it actually covers.
- The Dataflow Model (Akidau et al., 2015)Google (author copy) · required
Read the model section: event time versus processing time, windowing, triggers and accumulation. Implement one trigger and one accumulation mode, not the catalog.
- Apache Flink 2.3 - Event Time, State and CheckpointingApache Flink · required
Read the 2.3 concepts pages on time (event time, watermarks, lateness, windowing) and stateful stream processing (keyed state, checkpoint barriers, recovery, unaligned checkpoints, exactly-once versus at-least-once), then the watermark-generation guide on idle sources. Use them to build one bounded local processor; exactly-once covers state and participating sinks only.
Also in this section
- The Log: What Every Software Engineer Should Know About Real-time Data's Unifying Abstraction (Kreps, 2013)LinkedIn Engineering · support
Read it first as the short concept spine for logs, replicas, data integration and stream processing, before DDIA 2e Chapters 11 to 13.
- Kafka: a Distributed Messaging System for Log Processing (Kreps, Narkhede and Rao, 2011)NetDB workshop (mirror) · support
Read it as the design ancestor of your mini log: segments, offsets, pull consumers and consumer groups. Replication is future work in this paper, so take durability from the current docs.
- MillWheel: Fault-Tolerant Stream Processing at Internet Scale (Akidau et al., 2013)PVLDB · support
Read low watermarks, persistent state, strong productions and exactly-once delivery by deduplication. The deduplication holds only within its retention bound.
- Lightweight Asynchronous Snapshots for Distributed Dataflows (Carbone et al., 2015)arXiv · required
Read the asynchronous barrier snapshotting algorithm for acyclic graphs and its recovery; skip the cyclic extension. Barriers assume FIFO channels.
- Distributed Snapshots: Determining Global States of Distributed Systems (Chandy and Lamport, 1985)Leslie Lamport · support
Read the marker-sending and marker-receiving rules and why the recorded state is consistent. The algorithm needs FIFO channels.
- Apache Kafka 4.3 - Design, Log, Rebalance and Transaction ProtocolsApache Kafka · required
Read the 4.3 design page (replication and in-sync replicas, acknowledgements and
min.insync.replicas, delivery semantics, idempotence and transactions, the consumer, log compaction), the log implementation page, and the consumer rebalance protocol and transaction protocol pages (https://kafka.apache.org/43/operations/). Kafka 4.0 removed ZooKeeper. Run experiments in theapache/kafka:4.3.1image and compare each contract with your mini log. - Gossip Glomers - Kafka-Style LogFly.io and Jepsen · required
Each challenge runs locally under Maelstrom (v0.2.4; the pages were tested on 0.2.3) with its checker and, where the page says so, the partition nemesis; keep the run directory as the history. Do 5a to 5c:
send,poll,commit_offsetsandlist_committed_offsetson one node, then two nodes overlin-kv, then with fewer messages. The checker catches lost writes and nonmonotonic or skipped offsets; it does not check recency or exactly-once effects. - AWS Builders' Library - Avoiding Insurmountable Queue BacklogsAmazon Web Services · support
Read it for how backlogs grow and why they take long to drain, and for backpressure, prioritization, sidelining and constant work. Compare its recovery strategies with the bounded backlog and lag measurements of your consumer.
- Confluent Schema Registry - Schema Evolution and CompatibilityConfluent · support
Use only the compatibility-type definitions (backward, forward, full and their transitive forms) as the vocabulary for your schema checks, with the Avro schema resolution rules as the mechanism.
- HLD Handbook - Queues, Streaming, Stream vs Batch and CDCHLD Handbook · required
Read only Part 2 message queues and pub-sub plus Part 4 stream versus batch and change data capture. Use Part 5 event-driven architecture after the underlying log and replay contract is clear.
- MIT 6.5840 - Lab 1 MapReduceMIT PDOS · support
Complete or review the coordinator and worker lab to connect deterministic batch dataflow, task retries and output publication. Do not confuse its shared-filesystem assumptions with the durable log contract.
- Replicated Log and Stream Processor - Full Data PathRoadmap-Final · support
Complete partitioned log, producer identity, consumer ownership, offsets, backpressure, event-time state, checkpoint, replay and sink boundary. Run the required producer, consumer, storage and late-data fault campaign.
- Apache Iceberg - Table SpecificationApache Iceberg · reference
Read the snapshot, manifest list and manifest sections for the read path, and the table metadata section for the atomic metadata-file swap that commits a snapshot.
- Delta Lake Protocol (pinned commit)Delta Lake · reference
Read the transaction log replay and checkpoint sections for how readers reconstruct table state, and the concurrency section for the optimistic commit rule.
- Apache Avro 1.12.0 Specification - Schema ResolutionApache Avro · reference
Read Schema Resolution only: records match by field name, writer-only fields are ignored, reader-only fields are filled from defaults, plus the promotion rules.