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

Proposal: Add ActiveRecord optimistic locking integration to enable partial ordering of events #13

Open
jmileham opened this issue Feb 6, 2020 · 1 comment

Comments

@jmileham
Copy link
Member

jmileham commented Feb 6, 2020

The README says you shouldn't use Journaled for event sourcing because it doesn't provide ordering guarantees.

We propose to add an ability to ride on top of ActiveRecord Optimistic Locking's lock_version column to version events.

This is good because the semantics of optimistic locking are often what you want for a data model that needs to spin events off (avoiding data races from multiple writers is probably desirable, these models are important).

It's not necessarily ideal for every possible use case, though, because unless every single update to the ActiveRecord with a lock_version results in an event, there will be gaps in the version number in the events sent, which means you can't guarantee that you've received all the events in order before processing on the downstream side.

So in short, this isn't a complete solution to event sourcing because unless each event is data-complete irrespective of historical events in a given stream, a missing historical event could result in an incorrect computation, meaning the downstream couldn't compute confidently. But for use cases where you only need the latest value, this approach can ensure eventual consistency between OLTP database and the downstream data processing service.

@smudge
Copy link
Member

smudge commented Feb 6, 2020

For context on the Rails feature: https://api.rubyonrails.org/classes/ActiveRecord/Locking/Optimistic.html

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

No branches or pull requests

2 participants