← Lessons

quiz vs the machine

Platinum1820

Databases

Snapshot Isolation Internals

Each transaction reads a consistent snapshot built from row versions and a transaction list.

6 min read · advanced · beat Platinum to climb

Reading A Frozen World

Under snapshot isolation a transaction sees the database as it existed at a single point in time, ignoring changes from transactions that commit later. Readers never block writers and writers never block readers, because each reader looks at the appropriate version of every row.

How Versions Work

Multiversion concurrency control keeps multiple versions of a row, each stamped with the transaction that created it and, once superseded, the one that replaced it. The old versions live in the undo log or in the table itself.

The Snapshot

When a transaction starts its read view, it captures a list of which transactions had already committed. For any row it visits, it walks the version chain and picks the newest version whose creating transaction is in that committed set.

  • A version created by a still active transaction is invisible.
  • A version created after the snapshot is invisible.
  • The first version satisfying the snapshot is the one read.

Write Conflicts

If two snapshots both update the same row, the second to commit detects the conflict and aborts, the first committer wins rule, which keeps lost updates from slipping through.

Key idea

Snapshot isolation gives each transaction a point in time view by walking row version chains and a captured committed set, so reads never block, while first committer wins resolves write conflicts.

Check yourself

Answer to earn rating on the learn ladder.

1. How does a transaction pick which row version to read?

2. Why do readers not block writers under snapshot isolation?

3. What does the first committer wins rule prevent?