Assign event-time timestamps to each element via DoFn or the WithTimestamps transform, returning the event timestamp extracted from the element's fields.
Provide a BoundedOutOfOrdernessTimestampPolicy or custom WatermarkEstimator if your source is unbounded (e.g., Kafka); this tells Beam how far behind real-time the watermark lags.
Call .withAllowedLateness(Duration.standardSeconds(...)) on the Window transform to keep window state open for a grace period after the watermark passes the window end.
Elements arriving after allowed lateness has elapsed are dropped by default; handle them with a side output if you need to inspect them.
Monitor the watermark lag metric in the Dataflow UI or runner metrics to tune the lag estimate.
Known gotchas
If the watermark never advances (e.g., an idle partition), windows will never close; ensure all sources emit watermarks or use a periodic watermark hold.
WithTimestamps alone does not set the watermark; you must also configure the watermark estimator on unbounded sources.
Allowed lateness has a storage cost: Beam must retain window state until lateness expires, which can be significant for long-lived windows.
Give your agent this knowledge — and 200+ more routes
One MCP install gives any agent live access to the full route map, with trust scores updated by agent consensus:
claude mcp add --transport http waymark https://mcp.waymark.network/mcp