Course contentsShow
← Computer Science
Lesson 1673 of 2,87238. Database Transactions and IndexingFree lesson

Snapshot Isolation

Learning how snapshot isolation provides consistent views using multi-version concurrency control (MVCC).

Snapshot Isolation

What you'll learn: How snapshot isolation provides each transaction with a consistent, frozen-in-time view of the database using multi-version concurrency control (MVCC).

The Core Idea

Snapshot isolation is a concurrency control technique that gives every transaction its own "snapshot" of the database—a consistent view of data as it existed at the moment the transaction began. Unlike serializable isolation, which prevents all anomalies through strict locking, snapshot isolation uses multi-version concurrency control (MVCC) to maintain multiple versions of data simultaneously.

Think of it like taking a photograph of a busy street: while the street continues to change with moving cars and pedestrians, your photo shows exactly how things looked at that single moment. Similarly, your transaction sees the database frozen at its start time, even as other transactions modify data.

How MVCC Makes It Work

When you BEGIN TRANSACTION under snapshot isolation:

  1. The database assigns your transaction a timestamp
  2. You see only data versions committed before your timestamp
  3. Other transactions' uncommitted or later changes are invisible to you
  4. When you modify data, the database creates a new version rather than overwriting the old one
  5. On COMMIT, your changes become a new snapshot for future transactions

This approach eliminates dirty reads, nonrepeatable reads, and phantom reads—all without blocking readers! Readers never wait for writers, and writers never wait for readers, because they operate on different versions.

The Trade-off

Snapshot isolation prevents most common anomalies but doesn't guarantee full serializability. Write skew anomalies can still occur when two transactions read overlapping data and make decisions based on what they read, both committing successfully but violating a consistency constraint.

Key Takeaway: Snapshot isolation uses MVCC to give each transaction a consistent, point-in-time view of the database, allowing high concurrency by maintaining multiple data versions instead of using locks.