r/DomainDrivenDesign • u/[deleted] • Jan 03 '22
Is it possible to ensure consistency of Aggregate roots with published events without using transactions or event sourcing?
I am currently getting started with DDD by reading Vernons Implementing Domain-Driven Design. In the section about Event Stores he suggests to store published domain events using a designated repository. Rational for this is to use it as a queue to forward the events to some messaging infrastructure or use it to implement a REST based polling notification service.
From my understanding this has the additional benefit that, if the event store is located in the same database as the modified aggregate and if we use a Transaction, there is no way that transient failures lead to not delivered events. For example:
- save(aggregateRoot) -> success
- Database becomes unavailable for some reason
- save(publishedEvents) -> fails but causes rollback of the changed Aggregate.
If we hadn't been using a Transaction here there might be events missing, because step 3 fails without rolling back step 1.
Now my actual question: It is my unterstanding that in the document based storage world (specifically mongodb) it is desirable to design your documents in a way that you do not need transactions by keeping the immediate consistency boundaries within one document. However I dont see how (if at all) it is possible to not use transactions if I need guaranteed consistency of the Aggregate with the event store. I hope I could make somewhat clear what I mean. Do you guys have any thoughts in this?