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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.