Write Skew (Snapshot Isolation Anomaly)
In plain English
Plain definition
Write Skew happens when two transactions each look at the same set of rows, each decide their own change is safe based on what they saw, and then each write to a different row. Because they never touch the same row for writing, the database's snapshot isolation doesn't see a conflict and lets both commit — even though the combined effect breaks a rule that spans both rows, such as 'at least one doctor must always be on-call'.
Snapshot Isolation guarantees that a transaction reads from a consistent snapshot taken at its start time and that its writes do not conflict at the row-version level with concurrent writes (write-write conflicts abort via first-committer-wins). SI does not detect read-write conflicts between transactions that never touch the same rows for writing. Write Skew exploits exactly this gap: two transactions T1 and T2 each read a shared set of rows R, base a decision on the aggregate state of R, and then each write to a different row that individually satisfies a constraint but collectively violates it.
The textbook example is the on-call doctor problem: an invariant requires at least one doctor on-call at all times. T1 reads that Doctor A and Doctor B are both on-call and decides it is safe for A to go off-call. Concurrently, T2 reads the same snapshot and decides it is safe for B to go off-call. Neither transaction’s write conflicts with the other at the storage engine’s MVCC version-chain level (they touch disjoint rows), so both commit under standard SI, leaving zero doctors on-call. The underlying invariant was never encoded as a row-level constraint the database could enforce.
- Preventing Write Skew requires either explicit locking (
SELECT ... FOR UPDATEon the read set to force a write-write conflict), materialising a conflict through a dummy row update, or upgrading to Serializable Snapshot Isolation (SSI), which tracks rw-antidependencies (a read that could be invalidated by a later write) between concurrent transactions and aborts a transaction when it detects a dangerous structure of two adjacent rw-antidependencies, which can occur in a cycle; because not every such structure is part of an actual cycle, SSI accepts some false-positive aborts. - Serializable isolation has a price. SSI implementations (e.g., PostgreSQL’s
SERIALIZABLElevel) impose overhead viaSIREADlock tracking and increased abort rates under contention, so many systems deliberately run at SI for throughput and accept the anomaly risk, pushing invariant enforcement into application-level predicate locks or constraint triggers instead. - Distribution adds its own difficulty. In sharded or geo-replicated OLTP systems where snapshots are coordinated via a global timestamp oracle (such as TrueTime-style or HLC-derived snapshots), Write Skew becomes harder to reason about because the ‘concurrent’ window widens with replication lag, increasing the probability of overlapping snapshot reads across shards that each locally believe their write is safe.
A Write Skew risk signals that an invariant spans multiple rows or aggregates without a single serialization point. On large systems, common mitigations include collapsing the invariant into a single row (a counter or a materialised constraint row that every transaction must write to, forcing a genuine write-write conflict), using explicit advisory locks scoped to the invariant’s logical key, or accepting eventual repair via asynchronous invariant-checking jobs when strict prevention is too costly for the workload’s throughput requirements.
Legacy Reference
https://www.postgresql.org/docs/current/transaction-iso.htmlAbout this page
Was this useful?
Reports go to the site owner and are used to correct pages. Corrections are listed at /corrections.
Recommended reading
More from KBY that goes with this term.

