Late records arrive after the window closes; grace decides how long you still accept them.
orders.groupByKey()
.windowedBy(TimeWindows.ofSizeAndGrace(
Duration.ofMinutes(5), Duration.ofMinutes(1)))
.count()
.toStream()
.to("orders-per-5min");
A record 30s late is counted.
A record 90s late is dropped - and shows up in the
dropped-records metric rather than in your total.
Run this yourself in the Online Java Compiler, spin up a live REST API in the API Sandbox, or practise with Java interview questions.
Published 2026-08-11