← Lessons

quiz vs the machine

Gold1450

Databases

Multiversion Concurrency Control MVCC

MVCC keeps multiple versions of each row so readers never block writers and writers never block readers.

5 min read · core · beat Gold to climb

The Core Idea

Multiversion concurrency control, or MVCC, stores several versions of a row over time instead of overwriting it in place. A write creates a new version tagged with the writing transaction. Old versions linger until no one can still need them.

Readers See a Snapshot

Each transaction reads as of a consistent point in time. When it reads a row, MVCC returns the version that was committed and visible at that point, ignoring newer uncommitted or later versions. So a reader never waits for a writer and a writer never waits for a reader.

Visibility Rules

The database decides which version a transaction sees using transaction ids or timestamps. A version is visible if the transaction that created it committed before the reader's snapshot, and was not later superseded within that snapshot.

Cleaning Up

Obsolete versions accumulate and must be removed. This garbage collection, called vacuuming in some systems, reclaims versions no active transaction can still see. Neglecting it causes bloat and slow scans.

Key idea

MVCC keeps multiple row versions so each transaction reads a consistent snapshot, letting readers and writers proceed without blocking, at the cost of cleaning up old versions.

Check yourself

Answer to earn rating on the learn ladder.

1. What does a write do under MVCC?

2. Why do readers not block writers under MVCC?

3. What ongoing maintenance does MVCC require?