Serializable snapshot isolation
Read multiversion dependencies, recognize write skew, and understand SSI’s conservative detection of dangerous structures.
On this page
The question for today
What you’ll understand
- Construct a write-skew anomaly under snapshot isolation.
- Interpret read-write antidependencies and dangerous structures.
- Explain why serialization failures require complete transaction retries.
A stable snapshot is useful: repeated reads can agree even while other transactions update the database. But stability of each transaction’s view does not guarantee that all committed transactions fit some serial order. Serializable snapshot isolation retains multiversion reading while detecting dependency patterns that could create anomalies. Its rejections preserve an isolation contract, and an application must be prepared to recompute work after a serialization failure.
A consistent snapshot can still support incompatible decisions
Imagine two independent availability-controller rows, A and B, both marked active. Each controller transaction reads both rows and disables its own row only if another controller remains active. Starting from the same snapshot, each sees two active rows and writes a different row. Their write sets do not overlap, yet together they leave no active controller. A serial execution of these particular transactions would leave one active, because the second transaction would observe the first change and decline to disable itself.
This is write skew: the conflict is in what the transactions read and decide, rather than two writers replacing the same record. Predicate reads can create analogous dependencies when a concurrent transaction inserts or removes matching rows. Checking only write-write overlap misses them. Every decision-critical query must participate in the intended transaction and isolation regime. An administrative script or a second service using weaker guarantees can invalidate an application-level argument that assumed all relevant changes followed one discipline.
Dangerous structures are not arbitrary graph cycles
A read-write antidependency points from a transaction that read an older version or predicate result to a concurrent transaction whose change it did not observe. In a serialization graph, such an edge constrains the apparent serial order. Under snapshot isolation, a nonserializable cycle contains adjacent read-write antidependencies. SSI monitors dangerous structures of this form, with concurrency and commit-order reasoning, rather than simply aborting whenever any ordinary service graph has a cycle or any two transactions touch the same table.
A dangerous structure can exist without a complete serialization cycle, so conservative detection can produce serialization failures for executions that might otherwise have been serializable. The exact implementation uses additional rules to reduce unnecessary aborts while preserving safety. Do not interpret every rejection as proof that committed data was already corrupted. Also distinguish SSI’s read-dependency tracking from blocking locks: recording a predicate dependency need not block a writer in the way an exclusive lock does. Performance and memory costs still exist even without that blocking.
Handle rejection as a new computation
On a serialization failure, retry the entire logical database transaction with fresh reads and decision logic. Repeating only the final update can preserve the stale condition that caused the failure. Keep nontransactional side effects outside automatic retry or protect them with an explicit idempotency and delivery design. Apply bounded backoff and a retry budget so contention does not create an unbounded feedback loop. Monitor failures by query shape and contention hotspot while checking that all eventually accepted outcomes satisfy the invariant.
The probability lab illustrates only a test assumption. Reset, set success probability p to 0.2 and trials n to 3, predict the probability of at least one marked outcome, then Step. This exact binomial distribution treats outcomes as independent with one fixed probability; use a marked outcome to mean an assumed retry in three fixed test attempts. It does not model SSI’s dependency graph or claim real retries are independent. Shared hot records and retry feedback are reasons the real distribution can differ.
Work it through
Replay an availability write skew
A and B both start active. T1 and T2 read the same two-active snapshot. T1 sets A inactive, T2 sets B inactive, and assume ordinary snapshot isolation permits both disjoint writes. Compare the result with retrying T2 after T1 commits under a serializable execution.
Both snapshot reads report 1 + 1 = 2 active controllers. Each transaction concludes that disabling its own row leaves one other active controller.
Applying both disjoint writes yields 0 + 0 = 0 active controllers, violating the required count of at least one. Write-write conflict checking alone did not reject this schedule.
After T1 commits, a fresh T2 reads A inactive and B active, giving one. Its condition no longer permits disabling B, so the final active count remains one.
Fresh recomputation can preserve the invariant after a serializable rejection. A snapshot is internally consistent without guaranteeing a serializable combined history.
The living notebook
Explore the model
Interactive lab · probability
An assumed retry rate across fixed attempts
Reset, set success probability p = 0.2 and trials n = 3, predict at least one marked outcome, then Step. Marks represent assumed retries in three fixed independent attempts, not an SSI simulation or a variable-length retry process.
- Mean · np
- 5
- Variance · np(1−p)
- 2.5
- Total probability
- 1
These are exact binomial probabilities for independent trials with one fixed success probability. Playback tours the distribution; it does not resample outcomes. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.
Look forA binomial calculation depends on independence and fixed trials; real transaction conflict retries can be correlated.
Pause & reason
Check your understanding
Your turn
Try it yourself
For the lab’s assumed independent marked-outcome probability 0.2 in three fixed attempts, calculate the probability of no marks and at least one mark. Explain why that result does not establish the retry rate of three concurrent transactions touching the same hot record.
Take a moment to make a prediction or work it out on paper. Open a hint when you need one.
Give me a hint
Compute the complement using the probability 0.8 of an unmarked attempt.
Compare with the solution
No marks has probability 0.8 cubed = 0.512. At least one has probability 1 − 0.512 = 0.488, or 48.8%. Transactions contending for one record may have correlated outcomes and changing conflict probabilities, especially after backoff or workload changes. The binomial arithmetic is exact for its assumptions and cannot validate the SSI protocol or measure a production conflict rate.
Keep the idea
Take it with you
- Snapshot consistency does not imply serializable combined decisions.
- SSI uses specific read-write dependency structures and ordering conditions.
- Serialization failures require fresh logical transactions and bounded, side-effect-aware retries.
Read further
Original sources and deeper explanations to follow at your own pace.
Optional progress, saved in this browser when available. Revisit any lesson at any time.
Lesson not marked complete.