liveBook · Manning

Write skew

As explained in Clojure: The Essential Reference

Write skew is a concurrency anomaly in which transactions independently update different shared references while jointly violating a constraint.

Write skew is a concurrency anomaly in which transactions update different shared references while jointly violating a constraint that spans them. Snapshot isolation can allow each transaction’s individual work to appear valid even when their combined result is not. section 14.4

When a transaction depends on a constraint shared by multiple refs, use ensure to make that dependency part of the transaction’s consistency check. A conflicting change then causes the transaction to retry rather than silently accepting a stale observation. section 14.4

Protecting a honeypot threshold

A voting system stores honeypot and candidate counts in separate refs. Each batch calls (ensure (votes "honeypot")) before accepting votes while the honeypot count remains below five. Two concurrent batches produce {:total-votes 115, :winner "candidate-1", :fraud? true}; the shared threshold is incorporated into transaction validation. section 14.4

How Clojure: The Essential Reference covers it

How deep it goes
Defines the anomaly and works through a Clojure voting example, but does not develop a broader taxonomy of isolation anomalies.
Examples
Demonstrates concurrent voting batches sharing a honeypot threshold across separate refs.
What it assumes
Assumes familiarity with refs and isolated STM transactions, while illustrating the shared-constraint problem through a concrete example.
What you can do after
Diagnose shared-ref consistency risks and apply ensure when transaction validity depends on another ref.
How it connects
Connects write skew with snapshot isolation, STM transactions, refs, and ensure.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Clojure: The Essential Reference. The section links point to the parts of the book it draws on.