liveBook · Manning

Multi-version concurrency control

As explained in Latency

Multiversion concurrency control, or MVCC, is a database concurrency-control technique that maintains multiple versions of records so transactions can read consistent snapshots while concurrent writes proceed.

Multi-version concurrency control (MVCC) is an optimistic database concurrency-control technique that keeps timestamped versions of records. Transactions read a consistent snapshot based on their start time, while writes create new versions, allowing readers and writers to proceed concurrently with less lock contention. section 9.5.2 section 9.4.2

MVCC provides these operational properties and trade-offs:

  • Readers see committed data available in their snapshot rather than uncommitted or later changes. section 9.4.2
  • Writers create versions instead of blocking readers; conflicting transactions can be aborted to preserve consistency. section 9.5.2
  • Maintaining old versions increases storage requirements and requires garbage collection. section 9.5.2
  • Snapshot isolation prevents dirty and non-repeatable reads but still permits write skew, so it does not guarantee serializability. section 9.4.2

Versions within one transaction

A transaction initially stores key A as version v0 with value 1. Updating A to 2 marks v0 deleted and inserts v1; updating it again to 3 marks v1 deleted and inserts v2. The version chain represents the transaction's evolving database state. section 9.5.2

Figure 9.6 An example of multiversion concurrency control (MVCC) across two transactions. The steps are the same as in figure 9.5, but in the second transaction, we see how the database maintains multiple versions of the objects, which allows transactions to execute optimistically.

Trace two transactions through their reads, writes, and retained record versions to see how MVCC enables optimistic execution. section 9.5.2

How Latency covers it

How deep it goes
Explains snapshots, timestamped versions, conflict aborts, write skew, storage overhead, and garbage collection.
Examples
Uses timestamped record versions, customer orders, and a two-account write-skew scenario to illustrate behavior and limits.
What it assumes
Assumes transactions, concurrent execution, consistency, and isolation levels as the surrounding database concepts.
What you can do after
Evaluate snapshot-based concurrency by tracing versions, identifying conflicts, and recognizing when write skew defeats serializability.
How it connects
Connects optimistic concurrency control with snapshot isolation, transaction isolation, serializability, write skew, and garbage collection.

Also explained in

Compare how 4 books explain multi-version concurrency control →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Latency. The section links point to the parts of the book it draws on.