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

Ch7: mention a "compare-and-set" alternative to "repeatable read" #331

Open
Arseniy-Popov opened this issue Jan 5, 2022 · 1 comment
Open

Comments

@Arseniy-Popov
Copy link

Arseniy-Popov commented Jan 5, 2022

If I'm not mistaken, there is an alternative way to disallow concurrent updates of the same product that doesn't require going up an isolation level from the default "read committed". That way is to use version number increments in conjunction with the "UPDATE ... WHERE product.version = ..." query. If two transactions try to modify the same product, the second one waits for the first one to commit, executes the update, and returns with zero affected rows, because the product's version has already been incremented by the first transaction, at which point we roll back the second one in the app.

I believe it would benefit the reader to be pointed to this pattern, even if in a footnote. It's described as a "compare and set" way to prevent lost updates in the "Transactions" chapter of Kleppmann's "Designing Data-Intensive Applications". That chapter is a good source on transaction isolation to direct the reader at.

@Arseniy-Popov Arseniy-Popov changed the title Ch7: mention an alternative way with "read committed" Ch7: mention a "compare-and-set" alternative Feb 5, 2022
@Arseniy-Popov Arseniy-Popov changed the title Ch7: mention a "compare-and-set" alternative Ch7: mention a "compare-and-set" alternative to "repeatable read" Feb 5, 2022
@dbaber
Copy link

dbaber commented May 5, 2024

They also call this optimistic locking.

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