Optimistic locking with versions
medium 4 minRead an object and its version.
Video lesson · Chapter 1 of 5
Two editors open version seven
Two editors save revision five
1:15Reel
Theory
Read or listen first. About 1 min.
What it is
A conditional save carries both the new content and the revision the editor originally read. The store checks that revision in the same operation that publishes the change.
Two editors start from revision 5
Why it exists
Conflicting edits can be rare enough that holding a lock during editing would waste time. A failed comparison identifies the point where a fresh read and merge are needed.
Words to know
- Expected revision
- The version a caller believes is still current when it submits a conditional update.
How it works
Step through the idea, or press Play.
Read revision 5. Two editors start from the same revision.
Understand it
Worked example
Optimistic locking with versions in practice
A and B read revision 5. A publishes revision 6. B’s condition expecting 5 fails. B must reread revision 6 before deciding whether its original edit still makes sense.
Related case
Who gets the last reservation?
A library releases a limited print edition at noon. Thousands see one copy available. A customer can reserve it for two minutes while checking out.
Compare item, owner, state and deadline.