Concurrency Domain Event Issues

I have a series of domain events that can be sent to our corporate system. For example, if someone creates or deletes an address.

Should I pass the whole object as part of the event or just pass the id. Messages are sent over Service Bus and consumed in parallel.

If I just send the id, then the object might not be available on the consumer side if deletion occurs at that time. I can always just use the active flag and set it to false, but what about if the object was updated in the meantime and it changed something important.

How do I handle these cases?

+3


source to share


1 answer


I believe this is a common Service Bus dilemma and I believe there is no perfect solution. I am assuming that the scope here is ONLY events that occur when the state of important domain objects (i.e., non-transactional commands as well as read / data services) changes.

The decision to send only the event metadata as well as send a full reference message (like a new user's new root summary root) probably has wider implications than just concurrency / versioning issues related to latency, for example. some pros and cons of any approach:

Minimum metadata Event

:

  • Has a much lower payload (especially useful if you are checking all messages on the bus)
  • Fits into standard envelopes
  • Safe enough if delivered to an unauthorized bus endpoint (the whole system gets the information that the XYZ client has changed, not the actual data).

While a full "consolidated" root update Message



  • May be overkill if most subscribers are not interested in the full payload.
  • Potential Safety Issues - Not All Bus Subscribers May Be Eligible For Full Payload
  • But great for populating CQRS readstore caches, since endpoints don't need to go back to the source of truth to fetch data as soon as they know their data is out of date - the data has already been provided.

So, I think the final decision will be about what you are primarily going to do with your EDA events (update CQRS caches, update VG Triggering BPM Workflows, and control CEP rules, etc.). You might decide to go with a hybrid, for example. broadcast event data broadly, but then route full messages only to trusted endpoints (event metadata can probably be projected from the full payload, so the Originating / Source of Truth system can simply send a single message payload to the bus after each state change) ...

To answer the question of data consistency, I believe you will need to agree that the data will only be finally consistent, and these delays will lead to temporary inconsistencies in the enterprise. I believe the best example here is adding a hash or timestamp to every message received from the Source of Truth, which needs to be added to any Commands that used this version of the data as a guess.

Then, when the command processing system processes the command, it can then check that hash against the current "true" version (based on the actual line of the business system database, NOT against the readstore cache), and it will have to fail the command if the hash / timestamps are not coincide, i.e. optimistic concurrency pattern.

+2


source







All Articles