Snapshot isolation is a transaction isolation guarantee under which every transaction reads data from a consistent snapshot of the database as it existed at the moment the transaction started, and commits only if no concurrent transaction has already committed a write to the same items. In databases, it is a central concept of transactions because it gives readers a stable view without blocking writers, and writers without blocking readers.
Snapshot isolation prevents dirty reads, non-repeatable reads and most phantom reads, yet it is not fully serializable. Its best-known gap is write skew, an anomaly in which two transactions read overlapping data, write to different rows and together violate a constraint that each one checked individually.
How snapshot isolation works internally
Snapshot isolation is almost always implemented with multiversion concurrency control (MVCC). Instead of overwriting a row in place, an update creates a new row version tagged with the identifier or timestamp of the writing transaction, while older versions remain available to transactions that started earlier.
When a transaction begins, the engine records a start timestamp or a list of transactions that were still active. Every read then selects the newest version committed before that point, so the transaction sees a frozen, internally consistent state regardless of what other sessions commit later.
Writes are checked at commit time or at the moment of writing. Under the first-committer-wins rule, if another transaction has committed a change to the same row after the snapshot was taken, the later writer is aborted with a serialization or update-conflict error. Some engines apply a first-updater-wins variant, blocking the second writer until the first commits or rolls back.
The table below summarizes the moving parts of a typical implementation.
| Component | Purpose | Typical form |
|---|---|---|
| Row versions | Keep older states readable | Version chains in heap or undo log |
| Snapshot timestamp | Defines what a transaction can see | Transaction ID list or commit sequence number |
| Visibility rule | Selects the correct version per read | Newest version committed before snapshot |
| Write conflict check | Prevents lost updates | First-committer-wins or first-updater-wins |
| Garbage collection | Removes versions no snapshot needs | Vacuum, purge or version store cleanup |
Anomalies prevented and permitted
Snapshot isolation blocks the classic read anomalies because a transaction never sees uncommitted data and never sees data change underneath it. It also prevents the lost update anomaly on a single row, because two concurrent writers to the same row cannot both commit.
The guarantee breaks down when transactions write disjoint sets of rows based on overlapping reads. Neither writer conflicts with the other at the row level, so both commit, yet the combined result could never have arisen from any serial order. Read-only transactions can also observe a read-only anomaly, seeing a state that is inconsistent with any serial schedule.
| Anomaly | Prevented | Reason |
|---|---|---|
| Dirty read | Yes | Only committed versions are visible |
| Non-repeatable read | Yes | Snapshot does not change during the transaction |
| Phantom read | Yes, for reads | New rows are invisible to the old snapshot |
| Lost update | Yes | Write conflict check aborts the second writer |
| Write skew | No | Disjoint writes produce no row-level conflict |
| Read-only anomaly | No | Reader can see an order no serial schedule allows |
Snapshot isolation compared with standard isolation levels
The ANSI SQL standard defines isolation levels by the anomalies they forbid, and snapshot isolation does not map cleanly onto any of them. It is stronger than read committed and, in most respects, stronger than the standard’s repeatable read, yet weaker than true serializability. This mismatch has caused real confusion in product naming.
PostgreSQL implements snapshot isolation under the name Repeatable Read, and Oracle Database historically labeled its snapshot-based mode Serializable even though it permits write skew. SQL Server exposes it explicitly as the SNAPSHOT isolation level, which must be enabled per database. The comparison below shows where snapshot isolation sits.
| Isolation level | Read view | Write skew possible | Blocking between readers and writers |
|---|---|---|---|
| Read committed | New snapshot per statement | Yes | None with MVCC |
| Repeatable read (locking) | Locks held on read rows | Yes, via phantoms | Readers block writers |
| Snapshot isolation | One snapshot per transaction | Yes | None |
| Serializable snapshot isolation | One snapshot plus dependency tracking | No | None, aborts instead |
| Two-phase locking serializable | Locks plus predicate locks | No | Readers and writers block each other |
Handling write skew in practice
Applications that run under snapshot isolation must identify transactions whose correctness depends on reading one set of rows and writing another. Common cases include on-call scheduling, seat or room booking, balance checks across multiple accounts and uniqueness rules that are not backed by a constraint.
- Materialize the conflict by writing to a shared row, such as a counter or a lock record, so concurrent transactions collide.
- Use explicit row locks with
SELECT ... FOR UPDATEon the rows that the decision depends on. - Enforce the rule with a database constraint, such as a unique or exclusion constraint, rather than application logic.
- Switch the critical transactions to serializable isolation where the engine supports serializable snapshot isolation.
Serializable snapshot isolation, used by PostgreSQL at its Serializable level, keeps the non-blocking behavior of snapshots but tracks read-write dependencies between concurrent transactions and aborts one when a dangerous cycle appears. Applications must therefore be ready to retry aborted transactions, which is good practice under plain snapshot isolation as well.
Costs and operational trade-offs
The main benefit of snapshot isolation is high read concurrency: long reports and analytical queries can run alongside heavy write traffic without lock contention. The price is paid in storage, cleanup work and abort handling.
| Effect | Cause | Mitigation |
|---|---|---|
| Version storage growth | Old versions kept for active snapshots | Keep transactions short |
| Table and index bloat | Cleanup delayed by long transactions | Monitor oldest snapshot age |
| Update conflict errors | First-committer-wins aborts | Retry logic in the application |
| Stale reads in long transactions | Snapshot fixed at start | Restart long readers periodically |
A single forgotten session left idle in transaction can hold back garbage collection for the entire database, so monitoring the age of the oldest active snapshot is a routine operational duty wherever snapshot isolation is used.
In simple terms
Imagine that each person working with a shared spreadsheet receives a private photograph of it at the moment they start. They read from that photograph, so nothing shifts under them while they work, and nobody has to wait for anybody else. Snapshot isolation gives every transaction that kind of photograph.
When someone tries to save changes, the system checks whether another person already changed the same cells in the meantime. If so, the later save is refused and must be tried again. The weakness is that two people can change different cells that together break a shared rule, and the system will not notice.
A practical example
A hospital scheduling system requires that at least one doctor stays on call each night. Two doctors, both on call for the same shift, open the app at the same moment to request leave. Each transaction reads the schedule, sees two doctors on call and concludes that removing one is safe.
Under snapshot isolation, each transaction updates only its own row, so there is no write conflict and both commits succeed, leaving the shift with nobody on call. The development team fixed the defect by running the leave request at the Serializable level in PostgreSQL and adding automatic retries. In load tests with 500 concurrent requests, the system then aborted the second transaction in every conflicting pair, and the coverage rule held without any noticeable slowdown for ordinary reads.