cph-cachet / carp.core-kotlin

Infrastructure-agnostic framework for distributed data collection.
https://carp.cachet.dk/core/
MIT License
21 stars 3 forks source link

Allow repository interfaces to verify concurrent updates #398

Closed Whathecode closed 2 years ago

Whathecode commented 2 years ago

When multiple requests come in concurrently, it is currently possible for later updates to override previous updates.

While the data within a subsystem is still in a consistent state, expected changes by the client may be omitted. For example, calling RecruitmentService.InviteNewParticipantGroup multiple times can result in one request overriding changes of another competing request.

Using optimistic concurrency, a check can be done to verify whether changes are applied to the expected version of the aggregate root. A default retry mechanism is then to simply retry the full request on up-to-date state.

However, the InviteNewParticipantGroup call specifically has a side effect of sending out invitations. This is a related issue which needs to be accounted for, most likely, by only sending out the invitation on a successful repo update.

Whathecode commented 2 years ago

Issue #298 may be relevant when deciding on an exception to throw in case of concurrent DB updates.