To understand the issue I provide a simplified diagram of my system:
- Let's see the Business service allows you to create an account. It generates
1. Business event
. - The event is processed by the Integration service that sends information about it to the External service via
2. API request
. - The External service sends a
3. Webhook
with information that a new customer has been created. - Then the webhook is processed by the Integration service which converts it to
4. Integration event
.
Unfortunately, the integration event is supposed to add customers created in the External System. The purpose of this is that a new account can be created both in the Business Service as well as in the External Service. The data state should be synchronized in both services.
So I have 2 cases:
- Customer is created in the Business service so the cycle should be stopped after adding a customer to an external system
- Customer is created in the External service and the cycle should be stopped after adding it to the Business service
The customer create flow is just an example as there are many other cases where the same schema applies e.g. customer data update, customer purchase, customer purchase update, and so on.
I look for a generic solution that will allow me to detect somehow that cycle should be broken. I considered a few ideas:
- attach to the event some metadata with the source of an action and based on that break the cycle. The problem is that the information is lost after sending data to the External service.
- Calculate hash from the event payload but the problem I see the event may include e.g. timestamps or other date-like data generated dynamically. For example in the case of a customer creating timestamp from the Business service the External service may be different as the External service creates a timestamp on its own.