Cognitive Scaffold

Preparing your thinking workspace

arrow_back_ios_new
MENTAL MODEL · M6275

Optimistic Locking

Optimistic Locking
TechnicalHigh supportSoftware Engineering
Included
account_tree

Updated 2026-07-28

Loading revision record…

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.

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/5

Practice this model in one real situation:

Check to track your progress (stored locally)
Learning progress0%

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.

  • link
    zh.wikipedia.orghttps://zh.wikipedia.org/wiki/%E4%B9%90%E8%A7%82%E5%B9%B6%E5%8F%91%E6%8E%A7%E5%88%B6ZH · Explicit
    verified
account_treeGenealogyexpand_more

RELATED MODELS