Concurrency Handling
Concurrency exceptions when multiple processes or threads access and modify shared resources simultaneously. These exceptions happen because two or more operations conflict try to change same piece of data. Ecotone provides built-in support for concurrency handling.
In order to solve concurrent access, Ecotone implements Optimistic Locking.
Optimistic Locking
Each Event Sourcing Aggregate or Event Sourcing Saga has a version property that represents the current version of the resource. When modifications are made, the version is incremented. If two concurrent processes attempt to modify the same resource with different versions, a concurrency exception is raised. This is default behaviour, if we are using inbuilt Event Sourcing support.
Custom Repositories
In case of Custom Repositories, we may use Ecotone support for optimistic locking to raise the exception in the Repository.
Version will be passed to the repository, based on #[AggregateVersion] property inside the Aggregate/Saga.
We don't need to deal with increasing those on each action. Ecotone will increase it in our Saga/Aggregate automatically. We may also use inbuilt trait to avoid adding property manually.
Self Healing
To handle concurrency exceptions and ensure the system can self-heal, Ecotone offers retry mechanisms.
Last updated
Was this helpful?