Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement unit of work pattern for repositories #417

Open
Whathecode opened this issue Oct 21, 2022 · 1 comment
Open

Implement unit of work pattern for repositories #417

Whathecode opened this issue Oct 21, 2022 · 1 comment
Labels
feature New functionality.

Comments

@Whathecode
Copy link
Member

To safeguard against concurrent repository updates overwriting each other's changes, a version field was introduced in all snapshots that are expected to be updated atomically in repository updates.

With these modifications in place, infrastructures using CARP core can now verify on repository writes whether the version of the snapshots in the DB match those of the expected fromSnapshotVersion from the AR which is loaded in memory and on which edits were performed. If not, this means a concurrent incoming requests manipulated the same AR, and an exception can be thrown. This exception can be handled uniformly by retrying the whole request.

Could even more guidance be given, and potentially specific database technologies for transaction management be used, by implementing a unit of work pattern on repository interfaces?

For example, MongoDB has read isolation, which if units of work get communicated to repository calls, could be used to achieve the same as verifying the version field.

@Whathecode
Copy link
Member Author

Whathecode commented Jan 28, 2024

This may also be important to safeguard that a repository update and matching domain event which is published occur as one transaction.

Currently, if a repository call succeeds, but an event bus call fails before it reaches a messaging bus, the system will end up in an inconsistent state.

https://blog.codingmilitia.com/2020/04/13/aspnet-040-from-zero-to-overkill-event-driven-integration-transactional-outbox-pattern/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New functionality.
Projects
None yet
Development

No branches or pull requests

1 participant