We have a CQRS system where various command handlers are wired up to create events.
In some specific use cases, we have an event handler that is listening to events and communicating these events to an external system. Based on the recommendation, we are using an anti corruption layer to manage all sorts of communication to this black box entity so as to not allow the corruption to creep into our design.
The system works well in most cases except at times when we need to duplicate events. There are times when the same command has to be issued twice (due to various business requirements). In such situations, certain event handlers are required to de duplicate the events (based on certain attributes that are present in the event, say an ID) while certain other event handlers are required to process these events as if they are coming for the first time.
In other words, for certain events, we want to call this external system multiple times. While for certain others, we want to ignore this duplicate event since it has already processed. This is a very event handler specific configuration and our event handlers are split 50-50 on this.
I was wondering what the best way of de duplicating at the event handler level is.
One immediate way I could think of is, to have a key value store at the event processor level that keeps tabs on what it has processed and what it hasnt. The de duplication can then happen based on the values in the key value store. Is this the recommended approach.
I could also see using the ID at the command handler level and de duplicating at the axon server level, but that would mean, the event handlers that are expecting the ssecond event now no longer get these.
Is there anything anyone can recommend from a design perspective? Or does anyone have any opionions on which design may be better? Any help would be highly appreciated.