Concurrency Control

Aggregate Event Streams can be accessed and read by multiple threads simultaneously. This opens up the real potential for concurrency conflicts that, if left unchecked, could result in a random number of invalid Aggregate states. Consider a scenario when two threads attempt to modify the Event Stream at the same time, as shown in Figure A.10.

Image

Figure A.10. Two threads contending for the same instance of an Aggregate designed using A+ES

The simplest resolution to this situation is to use EventStoreConcurrencyException at step 4, allowing it to propagate all the way up to the ultimate client:

Get Implementing Domain-Driven Design now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.