Course contentsShow
← Databases & SQL
Lesson 735 of 1,9537. Transaction ManagementFree lesson

Multi-Version Concurrency Control Fundamentals

Understand how database engines store multiple versions of a single row to avoid blocking readers.

In this lesson, you will learn how databases use Multi-Version Concurrency Control (MVCC) to allow readers and writers to operate on the same data simultaneously without blocking each other.

The Locking Bottleneck

In traditional systems that rely strictly on locks, a "writer" (someone updating a row) would place a lock on that data. If a "reader" then tried to access that same row, the system would force the reader to wait until the writer finished. This creates a performance bottleneck: as your database grows, users spend more time waiting for locks to release rather than retrieving information.

The Magic of Snapshots

MVCC solves this by never actually overwriting the original data immediately. Instead, when a transaction updates a row, the database creates a new version of that row.

Imagine a row in a Users table:

  • Original: ID: 1, Name: 'Alice', Version: 1
  • Writer updates the name to 'Alicia': The database keeps the original row and adds a new one: ID: 1, Name: 'Alicia', Version: 2

Now, when a reader initiates a transaction, the database engine provides them with a snapshot of the data as it existed at the exact moment their transaction started. Even if a writer is currently modifying 'Alice' to 'Alicia', the reader simply looks at Version 1. Because the reader is looking at a static snapshot from the past, the writer can modify Version 2 without the reader ever being blocked.

Why This Matters

By keeping multiple versions, the database allows for "non-blocking reads." Writers continue to create new versions, and readers continue to see the consistent state of the database from the start of their own transaction. Eventually, the database engine runs a background process (often called "vacuuming" or "garbage collection") to remove the old versions that are no longer needed by any active transactions.

This design is the backbone of modern high-performance databases, as it enables high concurrency—allowing thousands of users to read and write data in total harmony without waiting for one another to finish.

Key Takeaway: MVCC enables high concurrency by allowing readers to access historical snapshots of data while writers create new versions, effectively eliminating the need for readers to wait on writers.