DT4: Streams, big data and file formats

Lesson 3 of 5 · reading 15–25 minutes; practice and project time is on the module page

Processing streams: windows and late events

🎯You'll be able to

Explain how stream processors group events into time windows, why event time differs from arrival time, and how watermarks decide when a window is complete.

🏠The everyday picture

A teacher collects homework due at 9 a.m. but accepts work up to 9:10 from students stuck in traffic. After 9:10, the pile is marked. A watermark is that 9:10.

📘What it really is

📝A worked example

Input (illustrative, worked by hand): 15-minute tumbling windows by event time, watermark = newest event time seen minus 5 minutes. Events arrive in this order: 10:02, 10:09, 10:14, 10:21, 10:13 (late), 10:23, 10:31, 10:12 (very late).

Expected output: after 10:21 arrives, the watermark is 10:16, so the 10:00–10:15 window closes with 3 orders (10:02, 10:09, 10:14). The 10:13 event arrives after that and is late. By the time 10:31 arrives, the watermark is 10:26, still inside the 10:15–10:30 window, which holds 10:21 and 10:23 so far. The 10:12 event is late too. With a 10-minute allowed lateness, both late events would be added and the first window updated to 5.

🌍Where it's used

📝Case scenario

A ticketing site counted sales per minute by processing time. When its message system slowed during a big release, a backlog of sales was processed together, and the chart showed a false spike two minutes after the real one. Switching to event time with a watermark put sales in the minute they happened.

🖱️Try it

Using the worked example's rules, add one more event at 10:36 after the 10:12 event. Say which window closes and what its count is. Success: the watermark becomes 10:31, so the 10:15–10:30 window closes with 2 orders.

⚠️Common mistakes

🛠️For your project

Not in the kit's tests. Use this lesson for the capstone's streaming design notes.

✅Quick check

What's the difference between event time and processing time?

Show the answer

Event time is when it happened; processing time is when the system saw it.

What does a watermark decide?

Show the answer

When a window is treated as complete and its result published.

← PreviousEvents and Kafka
ProLearners Assist