Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Production Usage] Question: How can I modify the state of the whole table triggered by an input message? #462

Open
akshatraika-moment opened this issue Sep 5, 2024 · 1 comment

Comments

@akshatraika-moment
Copy link

akshatraika-moment commented Sep 5, 2024

We are using Goka in production and have encountered a scenario where we need to clean up the state in a table topic when processing a specific message from our input topic. The use case involves two types of messages:

  • Data Packet: This message is used to update the state for a specific key, typically by appending new information to the existing state. For example: { Key: user, Value: data } => Goka Processor => { Key: user, Value: []data{data1, data2, data3} }

  • Delete Message: This message requires us to remove data across many keys.

The challenge we’re facing is as follows:

  • We want to maintain at-least-once processing semantics.

  • Upon receiving the delete message, we need to iterate over the entire table (preferably for that partition) and remove the relevant data from each key’s state. Then, we update the state for those keys.

  • We attempted to use the experimental visitor + VisitAll function, but it seems this approach doesn't work as expected. The VisitAll function generates internal events that are not processed until the processor releases the thread for handling the delete message. This creates a problem, as we need to read the delete message, update all affected states, and only then commit the offset for the delete message to ensure proper at-least-once semantics.

What would be the recommended approach to handle this?

@akshatraika-moment akshatraika-moment changed the title Question: How can I modify the state of the whole table by using a trigger? Question: How can I modify the state of the whole table triggered by an input message? Sep 5, 2024
@akshatraika-moment akshatraika-moment changed the title Question: How can I modify the state of the whole table triggered by an input message? [Production Usage] Question: How can I modify the state of the whole table triggered by an input message? Sep 5, 2024
@owenniles
Copy link

owenniles commented Sep 5, 2024

I have this use case as well.

One difficulty I've encountered using p.VisitAll to perform cleanup upon receiving the kind of multi-key cleanup message @akshatraika-moment has described is that we don't want to block the process callback/partition processor until p.VisitAll returns, but we also don't want to commit the cleanup message's offset until p.VisitAll returns.

If we block the processor, we find ourselves in a deadlock. p.VisitAll does not return until all of the visit events have been processed, but the some of the visit events will never be processed because one of the partition processors is blocked on p.VisitAll.

But if we don't block the processor callback/partition processor, then we lose at least once semantics. If the processor shuts down or rebalances after the multi-key cleanup message's offset is committed but before we've finished cleaning up, some of the visit events are lost forever.

We've considered using ctx.DeferCommit to maintain at least once semantics, but are concerned we would build up a large queue of uncommitted offsets. The idea would be to wait for p.VisitAll to return before committing any offsets after receiving a multi-key cleanup message. The concern about building up a large queue of uncommitted offsets comes from the fact that we have high throughput and a lot of unique keys on our input topic.

We would greatly appreciate any advice! Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants