Hi all - I have a question about how to evolve an ...
# troubleshooting
d
Hi all - I have a question about how to evolve an existing flink job to incorporate slow moving data The situation I'm working through looks something like this (img attached) .... and I'm unclear on how I should think about this slow moving data in this context 🤔
Is there a way to build what is essentially a "lookup table" from the slow moving data in a way that it can be accessed efficiently from the global window context?
note: the slow moving data wouldn't trigger a re-aggregation or anything... but I would want it to be factored into future aggregations
also: using the DataStream API
m
You will need to do another join. - but it would be better if you aggregate while data is keyed and with an incremental aggregator in map-reduce style before the global window.
d
Hey Marco - thanks for replying! a couple questions/comments • is a streaming join really a good idea here, where the interval between the fast moving data and the slow moving data might be up to 60 days? • > an incremental aggregator in map-reduce style ◦ I'm not sure this is a good fit in this case, because I need older events to fall out of the aggregate after 60 days. If I reduce as events come in, I don't think I can achieve that 🤔
m
You’re using event time, right?
✅ 1
I know this might sound silly, but I think one stream moving fast and the other slowly has no consequence. All that matters is that you have enough compute resources to process it. That’s why I suggested a keyed stream (parallel programming). If your stream is not keyed and you force all the data and computations into a global window then you are defeating the purpose of distributed parallel programming. Don’t try to imagine or prematurely optimize. Follow the parallel programming paradigm and trust it. It will work.
So try to do all the computations in a keyed manner, aggregate or reduce the data stream, and then after there is less data join the stream in a global window at the very end
I hope i explained clearly
d
hey Marco - thanks again gratitude thank you I think I'm struggling to state my problem clearly 🤔 My streams and computations are all keyed, and the global window assigner partitions the data for my aggregates appropriately (docs) > A global windows assigner assigns all elements with the same key to the same single global window. right? And I think the issue with adding another join here to incorporate the slow moving data, is that the aggregates need to be updated as soon as the two fast moving events arrive -- adding a second interval join that waits up to 60days for the slow moving data (which may never arrive) is... not really an option here because then my fully enriched stream would lag way way far behind... right?
The first two events happen in real time, and that's when my aggregates need to be updated But because my aggregates are over a 60 days window, I also need the historical data in my window to be joined against enriched with one extra piece of slow changing information, if that makes sense?
I also don't want the slow moving data to trigger any aggregations when it arrives -- only when a pair of fast moving events arrive
really appreciate you taking the time to put some brainpower into this thread ⭐
m
Yeah, it will be hard to understand without seeing the code. Can’t you store the slow 60 day old data in keyed state?
d
hi marco! Your comment about using "keyed state" led me to the docs for the BroadcastState pattern, and it sounds like this might be what I need
[BroadcastState] was introduced to support use cases where records of one stream need to be broadcasted to all downstream tasks, where they are used to maintain the same state among all subtasks. This state can then be accessed while processing records of a second stream
I'll let you know if I'm able to achieve my goals this way gratitude thank you
Hi marco - I just remembered I promised to followup here I solved our problem by replacing our GlobalWindow with Count(1) trigger by a KeyedCoProcessFunction with manually managed state/windows 🎉 if you're interested in more detail, I can probably provide an example of the general approach
rough description of the migration