call(back)

What Is MVCC?

What is multi-version concurrency control, and what problem does it solve?

Answer out loud in under a minute: a definition, one concrete example, and one pitfall or trade-off.

Hints

Hint 1

Think about what a reader sees while a writer is halfway through a transaction, and how versions make that answer stable.

Solution

Show the approach

The short version

Writers create a new version of a row instead of overwriting it; each version is stamped with the transaction that created it. A reader works against a snapshot — the set of versions committed when it started — so it sees a consistent state without taking locks and without blocking writers.

Example

A long report reads a table while a batch job updates it. Under MVCC the report sees the table as it was when the report began; the batch job's writes land as new versions and become visible to transactions that start afterwards.

Pitfall

Old versions pile up and must be garbage-collected (vacuumed); a long-running reader pins versions and makes that collection wait. Snapshot isolation also permits write skew — two transactions each reading the other's row and writing their own — which serializable isolation prevents at extra cost.

Asked at