MVCC Explained: Multi-Version Concurrency Control

With MVCC, readers see a snapshot and never block writers. How row versions, transaction ids and read views decide which version you see.

In this chapter

MVCC: readers do not block writers because old versions exist

MVCC: common questions

What is MVCC?

Multi-version concurrency control keeps several versions of a row so each transaction reads a consistent snapshot. Readers do not block writers, and writers do not block readers.

How is MVCC different in PostgreSQL and MySQL?

PostgreSQL writes a new row version in the table and VACUUM removes old ones. InnoDB updates the row in place and rebuilds old versions from the undo log.

More on Logs, versions and the buffer pool

Keep learning

Overview

chapters · logs, versions and the buffer pool MVCC: readers do not block writers because old versions exist A writer changes a row while a reader reads it, and neither waits. The database keeps old versions of the row and gives each reader the version its snapshot is allowed to see.

1. Two ways to keep old versions

(a) newest in place, old ones in an undo area table: id 7 · bal 500 created by 140 · pointer ↓ undo area (separate space) bal 400 · by 130 · ↓ bal 300 · by 120 · ↓ … (b) every version is a row in the table table pages bal 300 · created 120 deleted by 130 · dead once unneeded bal 400 · created 130 deleted by 140 bal 500 · created 140 deleted by – (current) ✓ Same three versions, two layouts. Every version carries the id of the transaction that created it. The trade-off (a) undo area (b) versions in table An UPDATE Copies old values out, edits the row in place Writes a whole new row, stamps the old one deleted Reading old data Follow pointers back through undo Cleanup removes Undo records Dead rows and their index entries Pain when cleanup lags Undo grows, long chains Table and index bloat

2. The snapshot and the visibility rule

Transaction ids on a number line. Ids below 100, the lowest active id, are visible. Between 100 and the next id 120, ids in the active list, 100 and 110, are hidden and the rest are visible. Ids at or above 120 are hidden because they started after the snapshot. ✓ committed before ✕ started after Visibility rule for a version created by transaction T T is me? ✓ visible T < lowest active? ✓ visible: committed before the snapshot T ≥ next id? ✕ hidden: started after

3. When the snapshot is taken: per statement or per transaction

Plain read versus locking read Plain SELECT FOR UPDATE, UPDATE, DELETE Snapshot version Latest committed version The row (see locks) If the row changed after my snapshot Sees the old value Acts on the new value, or aborts with a serialization error Secondary index entries usually carry no version stamps. A reader with an old snapshot must check the table row (or a per-page visibility hint), which is why a covering index is not always free.

4. Cleanup and the oldest snapshot

A background cleaner removes versions that no open snapshot can see. The oldest snapshot is the horizon: nothing newer may go. One idle session after BEGIN, a long report or a stuck backup pins it, and old versions pile up.

Check yourself

⚙ In real engines MySQL/InnoDB: style (a), undo log with roll pointers, purge threads: MVCC and purge, storage. PostgreSQL: style (b), tuples stamped xmin/xmax, cleaned by VACUUM: MVCC and vacuum, isolation.

Recap

Old versions live in an undo area (newest in place) or as extra rows in the table. The oldest open snapshot holds cleanup back: keep transactions short.

More courses

  • Jobs, linked to lessons — Browse jobs where every requirement links to the chapter that teaches it. See how ready you are, how long the gap takes to close, and which listings look stale.
  • Match a job post to courses — Paste a job post. Each skill is matched to a track here and put in learning order, foundations first.
  • React patterns from open source — Patterns extracted from Material UI, Radix, React Aria, React Hook Form, Redux Toolkit, TanStack, and Next.js — not slides about hooks.
  • System Design — Core concepts first (SQL vs NoSQL, CAP, indexing, replication, sharding), then designs grouped by what carries them: the database, Redis, Kafka, or many services.
  • NestJS: build a real API — One ticket-booking API, built in order: a plain Node server first, then NestJS modules, validation, a real database, and the features real clients lean on.
  • Microservices — Microservice patterns one diagram at a time: how to split a monolith, how services talk, and how data stays consistent without distributed transactions.
  • Kafka — A beginner-to-senior path through event logs, reliable delivery, production operations, and disaster recovery.
  • AI engineering for software engineers — Eight free reads, in order, for software engineers moving into AI: when to build an agent, how to build one, how to test it, and how the model works underneath.
  • Frontend system design — How a UI is sliced when it is a product, not a page: ownership of state, cache, routes, and what happens when the network lies.
  • TypeScript in depth — The type system as a design tool. Inference, narrowing, generics, and the errors that mean the model is wrong — not a catalog of utility types.
  • CSS in depth — See the box, then the page. Visual chapters from the box model through Flexbox surprises, Grid, selectors, and units, then backgrounds, shapes, and visual effects, each with a playground.
  • Accessibility — Foundations first (WCAG in plain words, semantic HTML, lists, alt text), then hands-on HTML labs, a full pass of WAI-ARIA 1.3, and a final fix-the-page challenge.
  • Docker — What an image is, why layers cache, and how containers find each other on a network.
  • Redis — Fifteen Redis patterns, one picture each: cache, session, lock, counter, rate limiter, queue, and when Redis is the wrong tool.
  • Kubernetes — Kubernetes from zero to operators: why it exists, Pods, Deployments and Services, then configuration, networking, storage, scheduling, scaling and security.
  • AWS — AWS networking in plain English. A VPC is a gated housing society: streets are subnets, the Internet Gateway is the main gate, and a route table is the signboard.
  • Networking: the NetRoute game — NetRoute is a packet logistics game. You wire up computers, switches, routers, firewalls and gateways, set each device, and watch glowing packets travel. If a packet gets dropped, the game shows you which header field was wrong.