Graph
Optimistic Concurrency Control

🔄Optimistic Concurrency Control

NEW

Also known as: OCC

A concurrency method that assumes few conflicts, allowing transactions to proceed and validating for conflicts at commit time.

DESCRIPTION

Optimistic Concurrency Control avoids locks during transaction execution, improving throughput in low-contention environments. Transactions proceed and validate read-write sets at commit, aborting on conflicts. Typical implementations use version numbers or timestamps to detect write skew. OCC suits distributed systems and user-driven workloads where contention is rare. It contrasts with pessimistic locking, which prevents conflicts by acquiring locks up front.

ALTERNATIVE DEFINITIONS

Wikipedia

Optimistic concurrency control (OCC), sometimes called optimistic locking, is a concurrency control method applied to transactional systems.

Introduces the method and alternate term optimistic locking.

Source

Microsoft Learn

Optimistic concurrency allows multiple processes to make changes to data and detects conflicts when an update is attempted.

Focuses on detection via concurrency tokens in application frameworks.

Source

Multiversion Concurrency Control Two-Phase Locking Transaction Isolation Levels Conflict Detection Versioning Deadlock Compare-and-Swap Commit Validation

COMPETING TERMS

Pessimistic Concurrency Control

KNOWLEDGE AREAS

Data Storage & Operations Software Engineering Data Engineering Data Architecture

TARGET AUDIENCE

Software Developer Data Engineer Data Architect Cloud Architect Data Modeler

EXTERNAL SOURCES

TOP QUESTIONS

When should Optimistic Concurrency Control be used?

Use OCC when contention is low, such as user-driven updates or distributed services with sparse conflicts. It yields higher throughput by avoiding locks during execution.

Category: Requirements

How does Optimistic Concurrency Control detect conflicts?

It validates read and write sets at commit using timestamps or version numbers. If another transaction has modified data, the commit fails and the transaction retries.

Category: Concepts

What is the main difference between OCC and pessimistic locking?

OCC defers conflict handling to commit-time checks; pessimistic locking prevents conflicts up front by acquiring locks, potentially reducing concurrency.

Category: Comparison

What are common OCC pitfalls?

High contention can cause frequent retries and degraded performance. Poor validation logic risks undetected conflicts and lost updates.

Category: Mistakes

How is OCC implemented in practice?

Systems track version identifiers per record and compare on update. Frameworks like EF Core use concurrency tokens to detect conflicts automatically.

Category: HowTo

Why is OCC relevant in distributed systems?

It avoids distributed locks and can scale better when conflicts are infrequent, reducing coordination overhead.

Category: Relevancy

Does OCC eliminate deadlocks?

Yes, OCC avoids deadlocks because it doesn’t hold locks during execution. However, it may increase transaction retries under contention.

Category: Misunderstanding

What workloads are a poor fit for OCC?

High-contention transactional workloads, hot rows, and intensive concurrent updates often favor pessimistic locking or partitioning strategies.

Category: Risk

How do isolation levels interact with OCC?

OCC can complement higher isolation levels by validating conflicts at commit, but strong isolation may still require careful design to avoid anomalies.

Category: Opinion