Closed jezzsantos closed 1 month ago
Synchronous relay of domain events (IDomainEvent
) is now acceptable within the same process as long as the process contains all subdomains of the same bounded context.
If we ever split the bounded context into separate deployable pieces, then we will need to send integration events (IIntegrationEvent
) that would then require asynchronous messaging and eventual consistency.
Thus, now we only need an integration event mechanism for communicating integration events across process boundaries.
As a first pass we've implemented a "synchronous" and "unreliable" mechanism to relay change events to read models and to notifications. It works "consistently", which is convenient, but it also naive.
See
InProcessSynchronousProjectionRelay
andInProcessSynchronousNotificationRelay
.These implementations (deliberately) do not model the intermediary message broker abstractions, that need to be represented in the architecture. They skip past that notional component entirely and do it in-process.
Furthermore, there is nothing fault-tolerant about them. If they fail to relay any event to any listener, they fail at that point, but the save of the events/snapshot has already succeeded.
This is really an acceptable outcome since half of the listeners may have processed the event and half have not. There is no replay capability and the push mechanism is not keeping track of progress for each listener. Also, for snapshot schemes, the events themselves are unrecoverable form memory!
Solution
These implementations need to be replaced (in a second pass) with more reliable and "asynchronous" versions of relays that involve an explicit message broker abstraction that when implemented, guarantees these things:
We have also to remember that there will be 2 implementations since the source of these change events could originate from either a snapshotting persistence store, or from an event-sourced persistence store.
IDataStore
adapter). This needs to cache the recent events until they are handed to the message broker.Reference materials: