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

Event time versus processing timeTumbling, sliding and session windows
1

Read

In this order, only the parts listed

0 of 3 done

  1. 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

  2. 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

  3. 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)

2

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.
3

Try it yourself

Closed-book, before checking anything

Closed-book, assign events at 10:03:39 and 10:08:12 to five-minute tumbling windows, five-minute hopping windows with a one-minute hop, five-minute sliding windows and session windows with a 30-minute gap, and state which windows they share.
4

Quiz yourself

Answer first, then mark it. Missed ones go to Review.

0 got · 0 missed

  1. 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. 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. 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. 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.

5

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