download

Why do 10-minute streaming windows drop late mobile events?

Data engineering~11 minReviewed 3 Dec 2026Free · No sign-in

Question

A streaming job counts clicks in 10-minute tumbling event-time windows, starting with [10:00, 10:10). The watermark tracks max_event_time - 2 min, and allowed lateness is 0.

Six events arrive in processing order:

EventEvent timeArrives atDelay
e110:0410:040 min
e210:0910:090 min
e310:1310:130 min
e410:0910:134 min
e510:1610:160 min
e610:0910:167 min
  1. Why does [10:00, 10:10) emit 2 clicks instead of 4?
  2. How do allowed_lateness = 3 min and a side output change the outcome for e4 and e6?
  3. What trade-offs come with raising watermark delay or allowed lateness?
Show hints (3)
  1. "TRACE THE WATERMARK"

    Update the watermark after each event as max(watermark, event_time - 2 min). Check which event pushes it past 10:10.

  2. "EXTEND WINDOW LIFE"

    With allowed_lateness = 3 min, window [10:00, 10:10) stays open until the watermark reaches 10:13. Check the watermark when e4 and e6 arrive.

  3. "CATCH EXPIRED EVENTS"

    Once the watermark passes 10:13, the window state is purged. Route older events to a side output instead of dropping them silently.

Show checked explanation

When e3 (10:13) arrives, the watermark jumps to 10:11, closing [10:00, 10:10) at 2 clicks and dropping both e4 and e6. Adding allowed_lateness = 3 min keeps the window open until watermark 10:13, so e4 updates the count to 3. Event e6 arrives at watermark 10:14 and goes to a side output for batch reconciliation.

"SOLUTION · PYTHON"
def process(events, wm_delay=2, allowed=3):
    wm = 0
    counts, late_out = {}, []
    for eid, ev_min in events:
        wm = max(wm, ev_min - wm_delay)
        end = (ev_min // 10 + 1) * 10
        if wm >= end + allowed:
            late_out.append(eid)
        else:
            counts[end] = counts.get(end, 0) + 1
    return counts, late_out


stream = [("e1", 4), ("e2", 9), ("e3", 13),
          ("e4", 9), ("e5", 16), ("e6", 9)]
print("default:", process(stream, allowed=0))
print("fixed:  ", process(stream, allowed=3))
"OUTPUT"
default: ({10: 2, 20: 2}, ['e4', 'e6'])
fixed:   ({10: 3, 20: 2}, ['e6'])

Author-checked on CPython 3.12.10: ran the watermark simulator, compared event-time vs processing-time windowing, and tested allowed lateness and side-output routing against Apache Flink and Beam documentation. Checked by an editor other than the author.

Walkthrough

Event-time windows group clicks by when the user tapped, not when the server received the packet. That matters on mobile networks, where tunnels and offline retries delay uploads by several minutes. Switching to processing time would misplace e4 and e6 into [10:10, 10:20), giving 2 clicks in the first window and 4 in the second.

A watermark tells the engine that event time has advanced and older windows can emit. Here the watermark moves forward monotonically as max(watermark, event_time - 2 min). Trace every event for [10:00, 10:10):

EventEvent timeWatermarkallowed=0allowed=3 min + side output
e1, e210:04, 10:0910:02, 10:07Count = 2Count = 2
e310:1310:11Fires [10:00, 10:10) = 2Fires [10:00, 10:10) = 2
e4 (4 min late)10:0910:11Dropped (10:11 >= 10:10)Accepted; re-fires 3 (10:11 < 10:13)
e510:1610:14[10:10, 10:20) count = 2Purges [10:00, 10:10) (10:14 >= 10:13)
e6 (7 min late)10:0910:14DroppedRouted to side output for batch merge

Three levers, three trade-offs:

  • Larger watermark delay (for example 10 min) catches more late clicks before the first emit, but delays every initial dashboard update by 8 extra minutes.
  • Allowed lateness (3 min here) keeps the first emit fast while letting e4 trigger a corrected update. You pay with extra window state in memory or disk, and downstream sinks must handle upserts or retractions instead of append-only writes.
  • Side output plus batch reconciliation bounds streaming state while preventing silent loss. Events past allowed_lateness, like e6 or a phone offline for hours, land in a late-events store and merge into warehouse tables on a scheduled job.

Common mistakes

  • Switching from event time to processing time to stop drops. That silently puts e4 and e6 into [10:10, 10:20) and skews traffic charts.
  • Setting watermark delay to hours so zero events are late. Every live metric then waits hours before emitting its first number.
  • Enabling allowed lateness while writing to an append-only sink. Re-firing [10:00, 10:10) appends both 2 and 3, turning one window into 5 clicks.
  • Leaving late data dropped after allowed lateness with no side output or metric. Mobile outages then disappear from revenue reports silently.

Follow-up questions

  • "What happens if one Kafka partition goes idle and sends no events for 15 minutes?" An operator's watermark is the minimum across all input partitions. One idle partition freezes the global watermark, stalling window emits until you configure idle-source detection so the engine temporarily ignores quiet partitions.
  • "How should downstream tables store re-fired results from allowed lateness?" Key the sink table by (window_start, metric_key) and upsert each re-fired total, or consume retraction plus update records. Append-only sinks double-count whenever a window re-fires.
  • "Why not set allowed lateness to 7 days so you never need a side output?" Every open window holds state until window_end + allowed_lateness. Keeping 7 days of 10-minute windows across millions of keys bloats state size, slows checkpoints, and hurts recovery time.

What a strong answer covers

Traces the watermark jumping to 10:11 on e3 and dropping e4 and e6. Combines a short watermark delay, bounded allowed lateness with upsert-safe sinks, and a side output for late reconciliation.

Open in interactive practice deck →

Original OfferVibe question. Apache Flink: Event Time and Watermarks · Apache Flink: Windows and Allowed Lateness · Apache Beam: Watermarks and Late Data.
© 2026 OfferVibe · Text CC BY-NC-SA 4.0 · code MITFree to share and adapt with credit, not for commercial use. Code samples are free for any use.