Replies: 2 comments 2 replies
-
@odrotbohm. Do you have any insights here? Is there, or could there be a way for consumers of modulith events to avoid holding a DB transaction open for the entire duration? |
Beta Was this translation helpful? Give feedback.
-
I think your jumping to specifics of a feature request too quickly. That said, if you don't need a transaction in the listener, simply use One thing you still seem to have not considered is what happens if one of the latter array elements results in an error and how you'd handle that. That's something crucial to the overall transaction handling for the listener but totally dependent on what you're trying to achieve. |
Beta Was this translation helpful? Give feedback.
-
When using the modulith, the @ApplicationModuleListener annotation adds a transaction around every workflow. This holds a DB connection open throughout the entire workflow. Suppose a workflow is as follows...
In the above example, the lengthy file I/O operations cause the database, and the maximum number of DB connections configured in your application, to become the bottleneck. Some options to address this problem:
Feature Request
Can the modulith event_publication table include another column to provide features similar to the SQS visibility timeout concept. The column can be a datetime and the event can only be consumed if the value is null or in the past. For discussion purposes, let's call the proposed column invisible_until. When inserting a new event the invisible_until column would start out as null. When the event gets picked it would update this column to now() + X where X would have to be some number of milliseconds configured by the user for the given event type. If the process finishes it updates the existing completion_date column. If the completion is finished within the allotted X milliseconds then that's the happy path case. If it does not finish within the allotted X milliseconds then a second thread could pick up the event. This runs the risk of multiple threads processing the event at the same time, and applications would need to have resiliency/idempotency built into their workflows, but this should already be the case for any event driven architecture.
Revisiting the workflow from earlier, we can now imagine something like...
Now we have the best of both worlds. The transactional outbox pattern is preserved while the lengthy file I/O operations are performed without holding onto a DB connection
Thoughts?
Beta Was this translation helpful? Give feedback.
All reactions