De duplication at the event handler level

Hello folks
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.

Thanks
Gaurav

Hi,

would it be possible to put a property into the event,
that contains the count? So you could still get multiple events and can distinguish them.

Best regards
Johnny.

Thank you for your response. It is possible to add properties. But the individual events are generally unaware of past invocations.

There needs to be something that has a system view of the entire application and multiple eventd

Hi Gaurav,

maybe I’m not fully understanding the problem, but if certain calls need to be made just once for a group of events and others for each event individually, isn’t that something you just need to implement on each event handler individually? And yes, if the invocation needs to be only once for a group, you’ll need some form of identification in these events and register the fact that for a specific identifier this call has already been made. This could be a key-value store, or if you’re in a Saga, then store it within the Saga. I wouldn’t use a Saga just for this, though.

Hope this makes sense.
Cheers,

Having a key value store makes sense. Thank you for clarifying.