We have the following high level DSL processing topology:
TimeWindows timeWindow = TimeWindows.of(windowDurationMs).advanceBy(windowAdvanceMs).until(retensionTimeMs);
KTable<Windowed<K>, Long> table1 = stream1.groupByKey().count(timeWindow, "Stream_1_Count_Store");
KTable<Windowed<K>, Long> table2 = stream2.groupByKey().count(timeWindow, "Stream_2_Count_Store");
KTable<Windowed<K>, Pair<Long,Long> joined = table1.leftJoin(table2, someValueJoiner, joinSerde, "Join_Store");
KTable<Windowed<SmallerKey>, Tuple<Long,Long,Long>> grouped = joined.groupBy(someSelector);
KTable<Windowed<SmallerKey>, Map<Long, Pair<Long,Long>>> aggregated = grouped.aggregate(initializer, adder, subtractor, aggValueSerde, "Agg_Store_Name")
In short, what we're doing above is:
- Counting events using a hopping window
- Doing a left join between the resulting KTables (left because of business logic)
- Grouping and changing the key and value: taking a component (Long) of the key and moving to the value
- Aggregating the resulting KTable to a final KTable, the aggregation object is a map from T to the two joined counters from step 1. Note that the size of the map is no more than 600 and usually much less.
The idea is to create windowed event counts and use these windowed keys for the join and aggregate operations (which in the KTable case don't have windows on such operations)
The problem is this: The state stores of the join and aggregate operations have no retention mechanism and cause a space explosion in the disk (RocksDB).
More specifically: The (hopping) windows cause a cartesian product on the keys and there's no mechanism to delete old windows.
The same problem will also occur if the KTable key were not windowed, but just a large enough amount of unique keys
Note that the state stores backing table1 and table2 have no space issue, this is because they are provided a windowed store by the DSL which manages dropping old windows. In the join and aggregate we treat the windowed keys as "any old key" and the DSL does the same and uses a non-windowed KeyValueStore.
This question is related to the following: KAFKA-4212, KAFKA-4273, confluent forum question
Are there any misunderstood concepts here? Is there a simple way to implement this topology using the DSL? If not, what's the suggested ways to implement it using the low level API?