MVCC: How Readers Avoid Blocking Writers

Keep the old version of a row alongside the new one, and a reader never has to wait for a writer.

MVCC: How Readers Avoid Blocking Writers

This module needs JavaScript: it steps through two transactions rather than showing a finished picture.

Worth knowing

A write does not overwrite. It writes a new version of the row and leaves the old one for whoever is still reading it.
Each transaction gets a snapshot: a rule for which versions it is allowed to see, fixed at the moment it started.
Readers never block writers and writers never block readers. Two writers to the same row still conflict.
The cost is garbage: dead versions accumulate and something has to clean them up. In PostgreSQL that is VACUUM.

Overview

Multi-Version Concurrency Control (MVCC) is a concurrency technique. Instead of overwriting a row in place for every change, the engine records enough version information to decide which version a transaction can see. A reader can then continue using a snapshot while another transaction writes, reducing some read-write blocking.

In this guide
  1. Why keep multiple versions
  2. Visibility is transaction-specific
  3. The cleanup cost
  4. MVCC does not remove all blocking
  5. Keep transactions short-lived
  6. Further reading

Why keep multiple versions

The exact implementation differs by engine. PostgreSQL stores tuple versions in the table and later reclaims obsolete versions; SQLite uses journaling or WAL snapshots with its own locking model. “MVCC” does not mean that every read and write happens without locks.

Visibility is transaction-specific

When a transaction reads a row, the database checks whether a version is visible according to the transaction's snapshot and isolation level. A second read may see a newer version under one isolation level and the same snapshot under another. This is why snapshot behavior and isolation guarantees need to be considered together. See isolation levels.

The cleanup cost

Old versions cannot be removed while active transactions may still need them. Long-running transactions can therefore delay cleanup and increase storage or maintenance work. In PostgreSQL, vacuum reclaims space from obsolete tuples for reuse and maintains visibility information. Monitor the engine's own maintenance signals rather than assuming MVCC is free.

MVCC can improve concurrency, but it does not prevent write-write conflicts, deadlocks, or every serialization anomaly. Use constraints and transaction logic to protect business rules; see transactions and ACID.

MVCC does not remove all blocking

Two transactions that update the same row still need to coordinate. DDL and explicit locks can block readers or writers, and a database may abort a transaction when its snapshot is no longer safe. In PostgreSQL, an update creates a new tuple version; old versions remain until no active transaction needs them and vacuum can reclaim them. In SQLite WAL mode, readers can continue on a snapshot while a writer commits, but SQLite still permits only one simultaneous writer. The label MVCC does not make engine behavior identical.

Keep transactions short-lived

A transaction that remains open while a user waits on a page or an external service can pin an old snapshot. That may delay cleanup of obsolete versions, increase storage, and make maintenance less effective. Fetch what is needed, commit, and do network work outside the transaction when consistency permits. If a workflow truly needs a long snapshot, monitor its duration and understand the engine's cleanup behavior. MVCC improves concurrent access, but old snapshots are resources the database must preserve.

Further reading

Check yourself

0 of 3

Answer without scrolling back up.

  1. What does a write do under MVCC?

  2. Which conflict does MVCC NOT remove?

  3. Why does an idle-in-transaction connection cause table bloat?

Cheat sheet

MVCC: How Readers Avoid Blocking Writers

Watch MVCC serve a reader an older row version while a writer updates the same row, and see why neither transaction has to wait for the other.

DATABASE · vizlearn.in/database/mvcc_in_databases.html

About the author

Ashish Jangra builds and maintains VizLearn. Every module here is written and the visualisation behind it hand-built, so the numbers in a readout come from the same code that draws the picture. Corrections are genuinely welcome and get priority over everything else — if a page states something wrong, or an animation misrepresents what the algorithm does, get in touch.

Teaching a course with this? Individual teachers can use it freely; for a whole department or programme, see institutional licences.