we are developing a CQRS application using Axon Server 4.2 with two Java microservices running the command and query sides. To back the persistent query model, we use a relational database.
Currently we are working on implementing cursor-based pagination for the query side (https://phauer.com/2018/web-api-pagination-timestamp-id-continuation-token/#continuation-token-approaches) and thus need to ensure a stable natural ordering of the entities in our tables.
Currently we’re using a single instance of our query-side application that uses a single TrackingEventProcessor with a SequentialPolicy to ensure that events are always processed in the same order. This however is starting to cause considerable read-model latency as complexity and load on our application grows. Thus we would like to switch to a TrackingEventProcessor with the default SequentialPerAggregatePolicy to speed up things and gain scalability for our query-side application.
Having a single instance and the SequentialPolicy in place made it easy for us to determine a stable, sequential identifier to be added to each database row when a new entity was created since the events are guaranteed to be processed strictly sequential in the order in which they appear in the event store and we could use a simple auto-increment field to have a sequence that is stable even when we reset the database and replay all events.
When switching to a SequentialPerAggregatePolicy this is not true anymore, since events will be processed in paralell and we cannot guarantee that they are processed in the same order when we reset the database and replay all events. We would need to rely on some sort of global index that is already persistent in the underlying event stream and thus will not change, like the token of the event store. From the Axon documentation on Event Handlers (https://docs.axoniq.io/reference-guide/implementing-domain-logic/event-handling/handling-events) we know that the @SequenceNumber is available as parameter, but this is only sequential within a single Aggregate instance.
Is there any simple way to get a “global” index (like the token) in the Event Handler that reflects the global order of the event in the event store?
Thans for your insights,