EventHandlers not properly working with SequentialPolicy

Hello

It’s me again with again EventHandlers :slight_smile:

We discovered that using a defaultSequencingPolicy = SequentialPolicy in combination with segmentation does not properly work. In our test application it does not work in 9 of 10 cases.
It can happen that when you start the application some events are processed fine and then all of a sudden the event handling stops working. It can also happen that you start the application and the event handlers are not triggered at all.
When you start launching 2 applications (2 threads each, 4 segements) one of the apps stops handling events and the other continues for a while. We though see in the logs messages like “Notifying handlers for phase XXXX”

We didn’t test the behaviour during a replay yet. What of course works totally fine is single threaded processing.

This whole thing seems pretty random. We do not see any exceptions and it’s a bit frustrating at this point. There are cases where we need to insure a sequential handling of events. At this point we do not have a lot of information we just observed this behaviour now for a while and cannot figure out exactly what is going on.
We even deleted tracking tokens and tried to “replay” everthing from scratch and the problems reoccurred.

Are there any known limitations (or issues) regarding SequentialPolicy and segmentation/multi-threaded event-handling? At least on github I couldn’t find anything nor in the documentation.

Kind regards
José

Hi José,

If there are any known issues regarding anything in the framework, I’d suggest to first check the issue tracker.
Any known problems should be documented in there and if they aren’t we add them as soon as possible.

However, I’d say that regarding using the SequentialPolicy as the SequencingPolicy there is no issue to be marked.
By using this policy, you’re ensured all the events will be handled by a single thread, as that’s the only way to fully ensure the events are handled sequentially.
Thus when leveraging this sequencing policy, segmented the event stream does nothing; all events will be put in the first segment.
From that you can conclude that if you want to multi thread your Tracking Event Processor by segmenting the Event Stream, you cannot use the SequentialPolicy at all.

I’d suggest to either use SequentialPerAggregatePolicy, which ensure all events for a given Aggregate identifier are handled in the same segment, or the FullConcurrencyPolicy, which does not impose any ordering to which segment an event should go.
Note that you can simply provide your own implementation of the SequencingPolicy as well.

Hope this helps you out José!

Cheers,
Steven

Hi Steven

Thanks a lot for your time and explanation. We were thinking that in case of SequentialPolicy some kind of round-robin approach is used since it worked during a replay and also for some thousands events (till it suddenly stopped processing).
For the case we need SequentialPolicy we are now using single threaded processing.

All the best,
José