Skip to main content
PYSPARK โ€ข LESSON 274

Event-Time Watermarking with withWatermark()

How can we instruct the streaming engine to discard late-arriving events older than 10 minutes and prune state memory?

Productionโฑ 3 Minutesโญ 830 XP
๐Ÿค” THE QUESTION

How can we instruct the streaming engine to discard late-arriving events older than 10 minutes and prune state memory?

๐Ÿ’ก WHAT IS IT?

withWatermark('event_time', '10 minutes') defines how late data can arrive before being ignored and cleans up internal state store.

๐ŸŽฏ WHAT IS IT USED FOR?

Preventing streaming cluster state stores from running out of memory during long-running 24/7 streaming jobs.

๐Ÿ’ป EXAMPLE
df_watermarked = streaming_df.withWatermark("event_timestamp", "10 minutes")

๐ŸŽฏ Mission Objectives

Practice typing production-grade PySpark code for Event-Time Watermarking with withWatermark().

  • โœ“ withWatermark() declaration
  • โœ“ Late-data threshold
  • โœ“ State store memory bounding