liveBook · Manning

Optimistic concurrency control

As explained in Data-Oriented Programming: Reduce software complexity

Optimistic concurrency control is a concurrency-control technique that allows operations to proceed without locking and detects or reconciles conflicts before committing changes.

Optimistic concurrency control lets concurrent mutations proceed without locks, then asks the commit phase to reconcile their results. Each calculation proceeds as if it were alone; the commit either accepts, merges, or aborts the mutation. This keeps reads and writes responsive, but moves complexity into conflict handling. section 5.1 section 5.6

A mutation follows this division of responsibility:

  • Calculate the next state in isolation without changing shared state. section 5.1
  • Commit by comparing the current, previous, and proposed states. section 5.5
  • Use a fast-forward when the current state still equals the previous state; otherwise attempt a three-way merge. section 5.5 section 5.6
  • Abort when concurrent changes overlap in a way the reconciliation algorithm cannot safely merge, then ask the user to retry. section 5.5 section 5.6

Two mutations, one shared state

Mutation A calculates from version P while mutation B commits first, producing version C. When A reaches commit, it compares P, C, and its proposed version N. If their changes use separate paths, it merges N into C; if they conflict, it throws a conflict and leaves C intact. section 5.5

Table 5.1 The two phases of a mutation with optimistic concurrency control (view table figure)

Phase

Responsibility

State

Implementation

Calculation

Compute next state in isolation

Stateless

Specific

Commit

Reconcile and update system state

Stateful

Common

The phase table makes the central trade-off visible: calculation is stateless and mutation-specific, while commit is stateful and shared. section 5.1

How Data-Oriented Programming: Reduce software complexity covers it

How deep it goes
Explains calculation, commit, fast-forward, three-way merge, structural differences, and aborts, but defers thread-safe implementation.
Examples
Uses immutable hash maps, path-based three-way merging, Git branch merging, and Elasticsearch as concrete reference points.
What it assumes
Assumes immutable state and multiversion mutations, while treating the calculation phase as already understood.
What you can do after
Apply it via a commit-phase reconciliation algorithm that merges safe changes and aborts irreconcilable mutations.
How it connects
Connects immutable data, multiversion state management, structural sharing, structural diff, three-way merge, and Git.

Also explained in

Compare how 3 books explain optimistic concurrency control →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Data-Oriented Programming: Reduce software complexity. The section links point to the parts of the book it draws on.