Optimistic Locking
Updated 2026-07-28
Summary
In relational database management systems, optimistic concurrency control (also known as "optimistic locking", abbreviated as "OCC") is a concurrency control method. It assumes that multi-user concurrent transactions will not affect each other during processing, and each transaction can process the part of data it affects without generating locks. Before committing data updates, each transaction first checks whether other transactions have modified the data after it was read. If other transactions have updated it, the committing transaction will roll back.
Definition
In relational database management systems, optimistic concurrency control (also known as "optimistic locking", abbreviated as "OCC") is a concurrency control method. It assumes that multi-user concurrent transactions will not affect each other during processing, and each transaction can process the part of data it affects without generating locks. Before committing data updates, each transaction first checks whether other transactions have modified the data after it was read. If other transactions have updated it, the committing transaction will roll back. Optimistic transaction control was first proposed by Professor H.T. Kung. Optimistic concurrency control is mostly used in environments with low data race and few conflicts. In such environments, the cost of occasionally rolling back transactions is lower than the cost of locking data when reading, thus achieving higher throughput than other concurrency control methods.
Introduction
How to use
In relational database management systems, optimistic concurrency control (also known as "optimistic locking", abbreviated as "OCC") is a concurrency control method. It assumes that multi-user concurrent transactions will not affect each other during processing, and each transaction can process the part of data it affects without generating locks. Before committing data updates, each transaction first checks whether other transactions have modified the data after it was read. If other transactions have updated it, the committing transaction will roll back.
Mechanism
Database concurrency control: assumes few conflicts, no locking when reading, and checks at commit time whether the data version/timestamp has been modified by others. If modified, conflict and retry. The mechanism is to replace "pre-locking" with "detect conflict + retry", significantly reducing blocking and improving throughput in read-heavy, write-light scenarios.
Practice
In progress 0/5Practice this model in one real situation:
Cases
- E-commerce inventory deduction uses version numbers to prevent overselling; collaborative document last-write validation; mapped to team "parallel work, resolve conflicts when merging".
Common pitfalls
- Frequent write conflicts cause retry storms and degrade performance; forgetting to handle conflict branches; treating optimistic as "lock-free" and ignoring retry costs.
Sources
Source support: Explicit
References currently contain only Wikipedia links; primary sources still need review.
- zh.wikipedia.orghttps://zh.wikipedia.org/wiki/%E4%B9%90%E8%A7%82%E5%B9%B6%E5%8F%91%E6%8E%A7%E5%88%B6verified
account_treeGenealogyexpand_more
PRIVATE NOTES · Only visible to you
SAVED Q&A
ENTRY Q&A · Private saving available
Ask with a clear boundary
thinkingmodels answers from published entry context only.
Your question is sent to thinkingmodels. The answer uses public entry context only.
RELATED MODELS