Optimistic Concurrency Control
September 01, 2019
Optimistic concurrency control (AKA optimistic locking) is a method that makes it possible to perform reading or updating a record without the use of the traditional locking mechanism by adding a version number and every time the data is updated, the version number increases. And Every time the client sends an update it has to send the version number. The version number gets checked to see if it has increased between the time of the client reads the data and the time it submits the update. If it did, then the update is rejected.
Real-world usage
- The sage pattern in microservice sometimes uses this method to overcome the lack of transaction isolation.
- All Kubernetes resources include a
metadata.resourceVersion
field, which clients need to pass back to the API server when updating an object.