write-skew · shipping

Write skew

Write skew is a concurrency anomaly in which transactions read overlapping data, write disjoint items and together break an invariant each would preserve alone.

Related Observatory article: Read on hesela.com

It is possible under snapshot isolation without a same-row write conflict. Checking only the versions of the rows being written does not validate every cross-row read dependency. [1]

Berenson et al. name it anomaly A5B in 1995. In their history two transactions each read x = 50 and y = 50 under a rule that x + y stays positive, then one writes y = -40, the other writes x = -40, and both commit. First-committer-wins does not stop this because the write sets do not overlap. [1]

Ports and Grittner describe two transactions that each see two doctors on call and each take a different one off call, leaving none. PostgreSQL 9.1 added Serializable Snapshot Isolation: commit ordering refines its detection of dangerous rw-antidependency pairs, and conservative detection can abort a serializable execution. The reported cost below 7% belongs to the paper's historical benchmarks, not a PostgreSQL 18 performance guarantee. [2]

In PostgreSQL 18, Repeatable Read lets both transactions in such a pattern commit, while Serializable rolls one back with SQLSTATE 40001 and the application must retry the complete transaction, including the decisions that selected its SQL and values. Another attempt may also fail. [5] [4]

Relations

related
Snapshot isolation, Serializability, Compare-and-swap, Serializable Snapshot Isolation, Optimistic concurrency control, Two-phase locking

Advantages

  • Naming the anomaly separates invariant failures across rows from lost updates on one row. [1]

Limitations

  • Explicit locks prevent it only when every transaction that touches the invariant takes them consistently. [4]

Citations

  1. Hal Berenson et al. A Critique of ANSI SQL Isolation Levels. ACM SIGMOD 1995; MSR-TR-95-51, section 4.2. (accessed 2026-10-22)
  2. Dan R. K. Ports and Kevin Grittner. Serializable Snapshot Isolation in PostgreSQL. PVLDB 5(12), 1850-1861, 2012, sections 2 and 4. arXiv:1208.4179v1. (accessed 2026-10-22)
  3. PostgreSQL 18 documentation, section 13.2: Transaction Isolation. (accessed 2026-10-22)
  4. PostgreSQL 18: Serialization Failure Handling, section 13.5. (accessed 2026-10-30)

Further reading

  1. Storage consistency: ordering is not a transaction or a durability promise (accessed 2026-10-12)
Sources & caveats
  • berenson-isolation is the 1995 SIGMOD paper by Berenson et al., read in section 4.2 on the access date.
  • ports-ssi is Ports and Grittner, PVLDB 2012, read in sections 1 to 3.
  • postgres-isolation is PostgreSQL 18 documentation section 13.2, read in the Repeatable Read and Serializable subsections.
  • 50, -40 and 1995 come from berenson-isolation. 9.1 and 7% come from ports-ssi. 40001 comes from postgres-isolation.
  • 2026-10-30: ports-ssi sections 3.2-4.1 and 5.4 checked for dangerous-structure false positives and commit-order refinements; postgres-retry checked for full-transaction replay and repeated conflicts.

JSON: /data/terms/write-skew.json

Published by Hesela team · Updated

Report a correction · Editorial standards · Reuse guidance

Cite this page
Hesela team. Write skew. Hesela. 2026-11-15. https://hesela.dev/terms/write-skew/