# TimeWindow flushing data instantly

**URL:** <https://forum.confluent.io/t/timewindow-flushing-data-instantly/3901>\
**Category:** Kafka Streams\
**Created:** [17 January 2022 07:44 UTC](https://forum.confluent.io/t/timewindow-flushing-data-instantly/3901 "2022-01-17T07:44:06Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![vishal165](https://avatars.discourse-cdn.com/v4/letter/v/e79b87/32.png) [@vishal165](https://forum.confluent.io/u/vishal165)\
**Post date:** [17 January 2022 07:44 UTC](https://forum.confluent.io/t/timewindow-flushing-data-instantly/3901/1 "2022-01-17T07:44:06Z")

</div>

I have a requirement to cont the number of packet for a time period based on certain key and published on a topic once the time period is elapsed.

for example i am getting packet in below pattern frequently

```auto
Rank	Time
1	1/10/2021 11:30:00
2	1/11/2021 11:31:00
1	1/10/2021 11:32:00
2	1/11/2021 11:33:00
2	1/11/2021 11:34:00

```

If i have a window of 5 minute then at every 5 minute , accumulated data should be published to a topic like

```auto
Rank Count
1 2
2. 3

```

---

<div class="post-metadata">

**Author:** ![mjsax](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.confluent.io/mjsax/32/3113_2.png) [@mjsax](https://forum.confluent.io/u/mjsax)\
**Post date:** [17 January 2022 18:42 UTC](https://forum.confluent.io/t/timewindow-flushing-data-instantly/3901/2 "2022-01-17T18:42:31Z")

</div>

You might want to use `suppress()` operator if you only want to get the final result.

---

<div class="post-metadata">

**Author:** ![vishal165](https://avatars.discourse-cdn.com/v4/letter/v/e79b87/32.png) [@vishal165](https://forum.confluent.io/u/vishal165)\
**Post date:** [18 January 2022 04:23 UTC](https://forum.confluent.io/t/timewindow-flushing-data-instantly/3901/3 "2022-01-18T04:23:38Z")

</div>

Thanks for your reply.

I am using the suppress but still final data is not holding back for specified window time. Below is my code snipped

```auto
KStream<String, Message> stream = kStreamsBuilder.stream("IN", Consumed.with(Serdes.String(), CustomSerdes.Message()));

KStream<Windowed<String>, Long> windowKStream = stream.groupBy((key, value) -> formGroupingKey(value))
                
                .windowedBy(TimeWindows.of(Duration.ofMinutes(60)))
               
                .count(Materialized.with(Serdes.String(), Serdes.Long())).suppress(Suppressed.untilTimeLimit(60, Suppressed.BufferConfig.unbounded())).toStream().to("OUT", Produced.with(Serdes.String(), CustomSerdes.OutData()));

```

---

<div class="post-metadata">

**Author:** ![mjsax](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.confluent.io/mjsax/32/3113_2.png) [@mjsax](https://forum.confluent.io/u/mjsax)\
**Post date:** [18 January 2022 18:48 UTC](https://forum.confluent.io/t/timewindow-flushing-data-instantly/3901/4 "2022-01-18T18:48:21Z")

</div>

You should use `untilWindowCloses()` instead of `untilTimeLimit()`.

---

<div class="post-metadata">

**Author:** ![vishal165](https://avatars.discourse-cdn.com/v4/letter/v/e79b87/32.png) [@vishal165](https://forum.confluent.io/u/vishal165)\
**Post date:** [20 January 2022 03:51 UTC](https://forum.confluent.io/t/timewindow-flushing-data-instantly/3901/5 "2022-01-20T03:51:57Z")

</div>

Thanks mjsax,

I have tried with `suppress(Suppressed.untilWindowCloses(Suppressed.BufferConfig.unbounded()))` but now data is not getting flushed out .

---

<div class="post-metadata">

**Author:** ![mjsax](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.confluent.io/mjsax/32/3113_2.png) [@mjsax](https://forum.confluent.io/u/mjsax)\
**Post date:** [20 January 2022 16:03 UTC](https://forum.confluent.io/t/timewindow-flushing-data-instantly/3901/6 "2022-01-20T16:03:44Z")

</div>

It will get flushed out when stream-time advances beyond window-close time (that is windowd-end plus grace-period). By default, grace-period is set to 24h though. You might want to reduce it via `TimeWindows.of(Duration.ofMinutes(60).grace(...))`.

Also note: it’s not based on wall-clock time; stream-time is only advanced when new records are processed.

---

<div class="post-metadata">

**Author:** ![vishal165](https://avatars.discourse-cdn.com/v4/letter/v/e79b87/32.png) [@vishal165](https://forum.confluent.io/u/vishal165)\
**Post date:** [21 January 2022 05:44 UTC](https://forum.confluent.io/t/timewindow-flushing-data-instantly/3901/7 "2022-01-21T05:44:07Z")

</div>

Thanks mjsax,

After adding grace time it is flushing out correctly.
