Hello, I’m considering a few possibilities for a Flink job, and would like to ask for insights from the community 🙏 There may have been gotchas that I’ve missed out or things I’m yet to be aware of.
Let’s say I have one event per min on a Kafka topic. I need to do some operations on the current element and an element from a certain time offset, X min ago.
Thinking about 2 options:
1.
2 consumers, one reading from latest offset, another reading from latest-X offset. Only the leading consumer will help move the event time on the operator.
Cons:
a. If we need to run the same logic for various offsets (5min, 1440min, 10080min, etc), there would be a fan-out issue (1 new consumer needed for each time offset). Perhaps we can split the topic into multiple smaller topics before applying the same logic on them.
b. Anything else that we need to be aware of if the offset is big? e.g. 24 hours? 7 days? Theoretically, as long as the retention time for the Kafka topic exceeds this, it seems fine…?
c. Perhaps can consider having 2 kafka topics (replicated), if there’s issues with the above.
2.
Use Statefun to send delayed messages (non-blocking, fault tolerant)
One single consumer, with 2 downstream operators, one operator process it as is, another operator sends delayed events to the first operator.
Question:
a. The same logic can be achieved by using a process function and storing all the elements within the time offset in a ListState (can get big if time offset is big); think ‘pseudo sliding window’.
But instead of having a big ListState, perhaps it’s more optimised/efficient when having a separate operator deal with the delayed events?
b. If we need to run the same logic for various offsets (5min, 1440min, 10080min etc, can be on separate threads, parallelism), would the Statefun delayed messages approach be scalable?
How does it fare/how does it work compared to Timers? (I’m not familiar with Statefun and would like to know what to watch out for. For timers, we can try RocksDB backend if it’s too much I guess).
Thank you very much 🙂