A topic in the Open Knowledge Graph — a free, open map of 15,290 topics and the order to learn them in.

Snapshot Isolation and Write Skew Anomalies

Graduate Depth 105 in the knowledge graph ☐ I know this ☆ Set as goal
411prerequisites beneath it
See this on the map →
Multi-Version Concurrency Control (MVCC)Transaction Isolation Levels: READ UNCOMMITTED to SERIALIZABLE→
snapshot-isolation write-skew anomaly SI phantom

Core Idea

Snapshot Isolation provides each transaction with a consistent database snapshot, preventing dirty, non-repeatable, and phantom reads. However, SI allows write skew anomalies where two transactions both read versions satisfying a constraint, make changes, and commit without noticing their combined effect violates the constraint (e.g., both doctors see the other on call, both go off). This anomaly cannot occur under SERIALIZABLE but is rare in practice.

Explainer

You already understand how MVCC works — each transaction sees a consistent snapshot of the database as of its start time, reading committed versions without blocking other writers. And you know that isolation levels define which anomalies a system permits. Snapshot isolation (SI) sits between REPEATABLE READ and SERIALIZABLE in strength: it prevents dirty reads, non-repeatable reads, and even phantom reads, because every read within the transaction returns data from the same fixed snapshot. Two concurrent transactions can both read and write without blocking each other, which makes SI attractive for performance.

The catch is write skew, an anomaly unique to snapshot isolation. Write skew occurs when two transactions each read an overlapping set of rows, make decisions based on what they read, and write to different rows — but their combined writes violate a constraint that held when each transaction read. The classic example involves two on-call doctors. A hospital rule says at least one doctor must remain on call. Doctor A and Doctor B both check the schedule at the same time, both see the other is on call, and both submit a request to go off call. Under snapshot isolation, each transaction sees the other doctor still on call (because neither has committed yet), so each concludes the constraint is satisfied. Both commit successfully, and now zero doctors are on call — violating the invariant.

The key insight is that write skew cannot happen if both transactions write to the same row. SI uses a first-committer-wins rule: if two transactions modify the same row, the second one to commit is aborted. This prevents lost updates. But write skew involves writing to *different* rows (Doctor A updates her own row, Doctor B updates his), so the conflict detection never fires. The transactions' writes do not overlap, even though their reads do, and the constraint violation emerges only from the combination.

Defending against write skew requires either upgrading to true SERIALIZABLE isolation (which detects these dependency cycles and aborts one transaction) or using application-level locking. A common workaround is to use SELECT FOR UPDATE on the rows you read, which forces a write lock even though you are only reading — effectively converting the read dependency into a write conflict that SI can detect. Some systems, like PostgreSQL's Serializable Snapshot Isolation (SSI), extend SI with dependency tracking to automatically detect and prevent write skew without requiring explicit locks.

Practice Questions 5 questions

Prerequisite Chain

Understanding Zero → The Number Zero → Counting to Five → Counting to 10 → Counting to 20 → Counting a Set of Objects Up to 20 → Cardinality: The Last Number Counted → Matching Numerals to Quantities → Subitizing Small Quantities → Addition Within 10 → Number Bonds to 10 → Addition Within 20 → Doubles and Near Doubles → Doubles Facts Within 10 → Near Doubles Facts Within 20 → Mental Math Strategies for Addition → Mental Math: Adding and Subtracting Tens → Addition Within 100 → Repeated Addition as Multiplication → Multiplication as Equal Groups → Multiplication: Arrays → Basic Multiplication Facts (0s, 1s, 2s, 5s, 10s) → Multiplication Facts Within 100 → Division as Equal Sharing → Division as Grouping (Measurement Division) → Division: Grouping (Repeated Subtraction) Model → Division: Fair Sharing Model → Division as Equal Sharing → Division as Grouping → Basic Division Facts → Division Facts Within 100 → Multiplication and Division Fact Families → Relationship Between Multiplication and Division → Division Facts as Inverse of Multiplication → Remainders and Quotients in Division → Division Word Problems → Multi-Step Word Problems → Solving Multi-Step Word Problems → Multiplication Word Problems → Division Word Problems → Introduction to Long Division → Factors and Multiples → Prime and Composite Numbers → Equivalent Fractions → Relating Fractions and Decimals → Decimal Place Value → Integers and the Number Line → Comparing and Ordering Integers → Absolute Value → Adding Integers → Subtracting Integers → Multiplying Integers → Introduction to Exponents → Order of Operations → Integer Order of Operations → Variable Expressions → The Distributive Property → Variables and Expressions Review → Introduction to Polynomials → Adding and Subtracting Polynomials → Multiplying Polynomials → Factorial → Permutations → Combinations → Counting Principles: Addition and Multiplication Rules → Introduction to Graph Theory → Propositional Logic Foundations → Logical Equivalences → Boolean Algebra → Boolean Type and Truth Values → Comparison Operators and Boolean Tests → Logical Operators and Boolean Algebra → Boolean Algebra and Fundamental Laws → Logic Gates Fundamentals → Implementing Boolean Functions with Gates → Karnaugh Map Simplification → Combinational Circuit Design → Flip-Flops and Latches → Binary Counters: Design and Analysis → Binary Arithmetic → Fixed-Point Number Representation → Two's Complement Representation → Overflow and Underflow Detection → Binary Adders: Half-Adders and Full-Adders → Full Adder and Carry Propagation → Carry Lookahead Adder Design → Half Adder Circuit Design → Multiplication Circuit Design → Sequential Circuit Design → Registers and Register Files → Instruction Set Architecture (ISA) → Kernel Architecture and OS Structure → System Calls and User/Kernel Mode → Processes and the Process Control Block → Process Creation: fork() and exec() → Process Termination and Resource Cleanup → Process States and State Transitions → Threads and Concurrency → The Critical Section Problem and Race Conditions → Mutual Exclusion and Locks → Concurrency Control in Databases → Lost Update Problem: Overwriting Concurrent Writes → Optimistic Concurrency Control: Version Numbers → Pessimistic Concurrency Control: Locking → Multi-Version Concurrency Control (MVCC) → Snapshot Isolation and Write Skew Anomalies

Longest path: 106 steps · 411 total prerequisite topics

Prerequisites (2)

Leads To (0)

No topics depend on this one yet.