Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kafka Streams - KTable from topic with retention policy

I'm experimenting with kafka streams and I have the following setup:

  • I have an existing kafka topic with a key space that is unbounded (but predictable and well known).
  • My topic has a retention policy (in bytes) to age out old records.
  • I'd like to materialize this topic into a Ktable where I can use the Interactive Queries API to retrieve records by key.

Is there any way to make my KTable "inherit" the retention policy from my topic? So that when records are aged out of the primary topic, they're no longer available in the ktable?

I'm worried about dumping all of the records into the KTable and having the StateStore grow unbounded.

One solution that I can think of is to transform into a windowed stream with hopping windows equal to a TimeToLive for the record, but I'm wondering if there's a better solution in a more native way.

Thanks.

like image 604
Kyle Fransham Avatar asked Jan 03 '18 15:01

Kyle Fransham


People also ask

How is KTable stored in Kafka?

Internally, a KTable is implemented using RocksDB and a topic in Kafka. RocksDB stores the current data of the table (note, that RocksDB is not an in-memory store, and can write to disk). At the same time, each update to the KTable (ie, to RocksDB) is written into the corresponding Kafka topic.

How does Kafka retention policy work?

Time Based RetentionUnder this policy, we configure the maximum time a Segment (hence messages) can live for. Once a Segment has spanned configured retention time, it is marked for deletion or compaction depending on configured cleanup policy. Default retention time for Segments is 7 days.

Is KTable in memory?

KTable is fully stored in RocksDB (== in memory) When KTable receive null-value record it deletes record from RocksDB (== memory freed up)


1 Answers

It is unfortunately not support atm. There is a JIRA though: https://issues.apache.org/jira/browse/KAFKA-4212

Another possibility would be to insert tombstone messages (<key,null>) into the input topic. The KTable would pick those up and delete the corresponding key from the store.

like image 172
Matthias J. Sax Avatar answered Sep 24 '22 03:09

Matthias J. Sax