Search code examples
apache-kafkaapache-kafka-streams

Session window how calculate gap?


I try to understand this shema of window session:

enter image description here

As I got right we have four events:

  1. 12:00:00 - event started in this time

  2. 12:00:25 - another event was ended

  3. 12:00:30 - event started in this time

  4. 12:00:50 - another event was ended

How do we get gap 15 seconds?

Could you explain what is start/end - is it one event or two different?


Solution

  • Events don't have a start or end time, but only a single scalar event-timestamp.

    If you use session windows, events that have a time difference to each other smaller than the gap parameter, fall into the same window.

    Thus, the start and end of a session window always corresponds to an event.

    Note that session windows are not designed for the case when you have dedicate start/end events in your input stream. Thinks of session windows more like a "session detection" scenario, i.e., you don't have sessions in your input stream, and want to sessionize your input data based on the record timestamps.

    Check out the docs for more details: https://docs.confluent.io/current/streams/developer-guide/dsl-api.html#session-windows