The following two properties must have a reliable system:
- P1: Published domain events MUST describe the change that has occurred (i.e., not trigger ghost events).
- P2: Changes to the database that trigger MUST domain events result in the publication of the event (i.e. do not lose the event).
There are the following possibilities for achieving this, all of which I either used myself or saw that it is used in the project:
Use a messaging infrastructure that uses the same database as your application so that you can use one transaction. This solution is viable when the messaging infrastructure is simple enough and the team decides to create it itself.
Use 2-phase fixations. I have no impression that this is no longer being used, but perhaps they are talking less about it because it is not fancy technology ...
Use some clever tricks to keep both conditions intact. For example. with what I call chicken and egg solution:
- First, publish events synchronously, and then save to the database. This provides P2.
- Then use an event processor that checks the flow of events and checks to see if the event can be found in the database. If not, remove the event from the stream. This ensures that P1 is executed.
Decision 3 requires careful development and analysis of the guarantees that each part of the system makes in terms of fault behavior, so law is probably the most difficult. But it is also a very elegant solution when it works.
By the way, I do not agree that Spring annotations should be added to domain objects, but rather to related applications. This is just a note.
theDmi
source share