Concurrency Control in Databases

College Depth 69 in the knowledge graph I know this Set as goal
Unlocks 16 downstream topics
concurrency control isolation levels dirty read phantom read MVCC serializability

Core Idea

Concurrency control ensures that concurrent transactions produce results equivalent to some serial execution, preventing read anomalies: dirty reads (reading uncommitted data), non-repeatable reads (a row changes between two reads in the same transaction), and phantom reads (new rows matching a predicate appear between reads). The SQL standard defines four isolation levels — READ UNCOMMITTED, READ COMMITTED, REPEATABLE READ, SERIALIZABLE — that progressively prevent more anomalies at increasing performance cost. Multi-Version Concurrency Control (MVCC) allows readers to see a consistent snapshot without blocking writers by maintaining multiple versions of each row.

How It's Best Learned

Reproduce read anomalies experimentally with two database sessions: start a transaction in one, modify data, then read from the other before committing. Switch isolation levels and observe which anomalies are prevented.

Common Misconceptions

Explainer

When two transactions execute against the same database simultaneously, their reads and writes can interleave in ways that produce surprising results — results that would never occur if the transactions ran one after the other. Concurrency control defines how the database manages these interactions. The goal is serializability: the outcome of concurrent transactions should be equivalent to *some* serial ordering, even though they actually ran in parallel.

Three classic read anomalies mark the failure modes. A dirty read occurs when transaction A reads data that transaction B has written but not yet committed — if B rolls back, A has read data that never officially existed. A non-repeatable read occurs when A reads a row, B updates and commits it, and A reads it again to get a different value within the same transaction. A phantom read is similar but involves rows disappearing or appearing: A queries for all rows matching a predicate, B inserts a matching row and commits, and A's second query finds a different set of rows.

The SQL standard defines four isolation levels that progressively prevent more anomalies. READ UNCOMMITTED allows all three anomalies (rarely used). READ COMMITTED (the default in PostgreSQL and Oracle) prevents dirty reads. REPEATABLE READ additionally prevents non-repeatable reads. SERIALIZABLE prevents all three, including phantom reads, at the cost of reduced throughput and potential transaction aborts. Choosing an isolation level is always a tradeoff between data consistency and performance.

MVCC (Multi-Version Concurrency Control) is the mechanism most modern databases use to implement these guarantees efficiently. Instead of locking rows so readers and writers block each other, MVCC maintains multiple timestamped versions of each row. When a transaction starts, it receives a snapshot timestamp and reads whichever row version was current at that moment. Writers create new versions without overwriting old ones. Because readers and writers operate on different versions, they never block each other — a long-running read query does not stall writes, and writes do not interrupt reads.

Understanding concurrency control ties directly back to the Isolation property in ACID: each transaction should appear to execute in isolation from others. The isolation levels are essentially a dial that trades more isolation for more performance. Most applications run at READ COMMITTED and handle residual anomalies at the application level, but correctness-critical operations (bank transfers, inventory updates) require REPEATABLE READ or SERIALIZABLE to avoid subtle bugs.

Practice Questions 3 questions

Prerequisite Chain

Counting to 10Counting to 20Understanding ZeroThe Number ZeroCounting to FiveOne-to-One CorrespondenceCombining Small Groups Within 5Addition Within 10Addition Within 20Two-Digit Addition Without RegroupingTwo-Digit Addition with RegroupingAddition Within 100Repeated Addition as MultiplicationMultiplication Facts Within 100Division as Equal SharingDivision as Grouping (Measurement Division)Division: Grouping (Repeated Subtraction) ModelDivision: Fair Sharing ModelDivision as Equal SharingDivision as GroupingBasic Division FactsDivision Facts Within 100Two-Digit by One-Digit DivisionDivision with RemaindersRemainders and Quotients in DivisionDivision Word ProblemsIntroduction to Long DivisionFactors and MultiplesPrime and Composite NumbersEquivalent FractionsRelating Fractions and DecimalsDecimal Place ValueReading and Writing DecimalsComparing and Ordering DecimalsAdding and Subtracting DecimalsMultiplying DecimalsDividing DecimalsDividing FractionsMixed Number ArithmeticOrder of OperationsOperators and ExpressionsArithmetic Operators and Operator PrecedenceComparison Operators and Boolean TestsLogical Operators and Boolean AlgebraBoolean Algebra and Fundamental LawsCombinational Circuit DesignFlip-Flops and LatchesBinary Counters: Design and AnalysisBinary ArithmeticFixed-Point Number RepresentationTwo's Complement RepresentationOverflow and Underflow DetectionBinary Adders: Half-Adders and Full-AddersFull Adder and Carry PropagationCarry Lookahead Adder DesignHalf Adder Circuit DesignMultiplication Circuit DesignSequential Circuit DesignRegisters and Register FilesInstruction Set Architecture (ISA)Kernel Architecture and OS StructureSystem Calls and User/Kernel ModeProcesses and the Process Control BlockProcess Creation: fork() and exec()Process Termination and Resource CleanupProcess States and State TransitionsThreads and ConcurrencyThe Critical Section Problem and Race ConditionsMutual Exclusion and LocksConcurrency Control in Databases

Longest path: 70 steps · 274 total prerequisite topics

Prerequisites (3)

Leads To (8)