# Kafka streams Session Window help

**URL:** <https://forum.confluent.io/t/kafka-streams-session-window-help/6318>\
**Category:** Kafka Streams\
**Created:** [20 October 2022 18:35 UTC](https://forum.confluent.io/t/kafka-streams-session-window-help/6318 "2022-10-20T18:35:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bran](https://avatars.discourse-cdn.com/v4/letter/b/e56c9b/32.png) [@bran](https://forum.confluent.io/u/bran)\
**Post date:** [20 October 2022 18:35 UTC](https://forum.confluent.io/t/kafka-streams-session-window-help/6318/1 "2022-10-20T18:35:20Z")

</div>

In a session window, I am unclear when I get the results. How do I know when the session for a particular key has ended? When do I get the results so that I can take the aggregated results and do further processing. For example … if I want to get the total count of a user’s errors. Each user would have their own session by the key. Once the 5 minute window and 30 second grace period has ended. I would expect to get the final event with the user data and the total count within that window. I only see the events as they happen within the window…not the final tally or when the window closed.

```auto
public void process(KStream<String, UserEvent> input) {
        input.peek((k,v) -> log.info("Key = " + k + " Create Time = "
            + Instant.ofEpochMilli(v.getCreatedTime()).atOffset(ZoneOffset.UTC)))
                .groupByKey()
                .windowedBy(SessionWindows.ofInactivityGapAndGrace(Duration.ofMinutes(5), Duration.ofMinutes(1)))
                .count()
                //.suppress(Suppressed.untilWindowCloses(Suppressed.BufferConfig.unbounded()))
                .suppress(Suppressed.untilTimeLimit(Duration.ofMinutes(5), Suppressed.BufferConfig.unbounded()))
                .toStream()
                .foreach((k,v) -> log.info(
                        "UserID: " + k.key() +
                        " Window start: " + Instant.ofEpochMilli(k.window().start()).atOffset(ZoneOffset.UTC) +
                        " Window end: " + Instant.ofEpochMilli(k.window().end()).atOffset(ZoneOffset.UTC) +
                        " Count: " + v + " Window#: " + k.window().hashCode()));
    }

```

My logs show events, but I expect to only see an event per key once the window+grace has expired…so that I can take the key and the summary and do further processing.

---

<div class="post-metadata">

**Author:** ![bbejeck](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.confluent.io/bbejeck/32/412_2.png) [@bbejeck](https://forum.confluent.io/u/bbejeck)\
**Post date:** [7 December 2022 21:54 UTC](https://forum.confluent.io/t/kafka-streams-session-window-help/6318/2 "2022-12-07T21:54:27Z")

</div>

Hi @bran,

Based on what you have here, this looks like it should work. Have you confirmed the timestamps for your records? Maybe you can try this out with the [TopologyTestDriver](https://docs.confluent.io/platform/current/streams/developer-guide/test-streams.html#testing-a-streams-application), which will allow you to set your timestamps per record, that way you can orchestrate the exact scenario you’re looking to achieve.

HTH,  
Bill
