Multi-Version Concurrency Control (MVCC)

Summary: A technique used to implement snapshot isolation by maintaining multiple versions of data objects.

Sources: chapter7

Last updated: 2026-04-17


MVCC allows a database to provide snapshot-isolation by keeping track of multiple versions of an object concurrently. This ensures that readers never block writers, and writers never block readers (source: chapter7).

Implementation Details

In a typical MVCC implementation (like PostgreSQL), when a transaction is started, it is given a unique, always-increasing transaction ID (txid). Whenever a transaction writes anything to the database, the data it writes is tagged with the transaction ID of the writer (source: chapter7).

Each row in a table has a created_by field (the txid of the transaction that inserted it) and a deleted_by field (initially empty, set when a transaction deletes it). An update is internally translated into a delete and a create (source: chapter7).

Visibility Rules

By carefully defining visibility rules based on transaction IDs, the database can present a consistent snapshot to each transaction. An object is visible if:

  1. At the start of the reader’s transaction, the transaction that created the object had already committed.
  2. The object is not marked for deletion, or if it is, the transaction that requested deletion had not yet committed at the start of the reader’s transaction.