Data Engineering Reference/Stream Processing

Event Time, Windows & Watermarks

Processing time vs event time, tumbling/sliding/session windows, watermarks for late data, and why wall-clock assumptions fail in distributed ingest.

4/5Overview: 30m

Processing time vs event time

Time typeDefinitionProblem
Processing timeWhen the pipeline processes the eventNon-deterministic on retry/replay
Event timeWhen the event actually happened (timestamp field)Requires handling out-of-order delivery

Production aggregations almost always use event time for correctness.

Windows

WindowUse case
TumblingFixed, non-overlapping (5-min error rate)
SlidingOverlapping (1-hour count updated every minute)
SessionGap-based (user activity until 30 min idle)

Watermarks

A watermark declares how late event-time data can arrive:

Watermark = max_event_time_seen - allowed_lateness

When watermark passes window end, the window closes and late data is dropped or sent to a side output.

Trade-off:

  • Tight watermark — low latency, drops late data
  • Loose watermark — correct but slow results

Stream joins (hard mode)

JoinChallenge
Stream-streamBuffer both sides until watermark
Stream-tableBroadcast/static dimension table
Stream-table (CDC)Dimension changes over time — needs versioned state

Link to Distributed Systems (Kafka semantics) — log ordering and consumer offsets underpin replay.

Interview answer template

"Clickstream events can arrive 15 minutes late from mobile offline buffers. I'd use event-time tumbling windows with a 20-minute watermark and a side output for very-late events to a correction job."

Further Reading

Hands-On Tasks (Optional)

Pipeline design drills and whiteboard exercises — DAG sketches, partition plans, backfill strategies. Assumes Databases and SQL fundamentals are in place.

  • Pick a window type

    For: (1) 5-minute error rate, (2) user session length, (3) rolling 1-hour unique users — choose tumbling, sliding, or session window and define event-time watermark policy.

    15m