System Design
5. Advanced Database ArchitectureAnimated
Optimistic Concurrency Control
Assume no conflicts; check at commit.
The idea
Transactions work on a snapshot and validate at the end. If someone else changed the data, retry.
Watch it work
Press play, pause, or step through. Some animations have settings you can change.
- current message
- earlier
- failure or attack
Both transactions read without locking.
- step:
- 1/6
- from:
- Txn A
- to:
- Database
1/6
Time runs downward. Solid arrows are requests, dashed arrows are replies.
Step by step
- 1Read data and a version
- 2Do the work
- 3At commit check the version
- 4If changed, abort and retry
Where it is used
Low-contention workloads.
Watch out for
Retries explode under high contention.