Concurrency Control Theory in Databases
Before we understand what concurrency control is and what problem it solves, let's start with how computers execute programs — and in order to understand that, we need to understand what a processor is.
The Engine: What a Processor Is
A processor (or CPU) is the central engine of a computer. Its job is to retrieve instructions from software, perform mathematical and logical calculations, and direct how data moves through memory — executing tasks step-by-step.
It processes instructions through a simple loop: fetch the next instruction from memory, decode what it asks for, execute it, and write the result back. This loop is paced by the processor's clock — billions of times per second. Everything a database does — reading a page, comparing values, writing a balance — ultimately reduces to these cycles.
Running a Database on an 8-Core Processor Without Concurrency Control
If a database runs on an 8-core processor with no concurrency control, all 8 cores execute incoming user queries simultaneously, in parallel hardware streams.
When two or more cores touch the exact same record at the same instant, their raw reads and writes interleave without coordination. Say two roommates each send $25 from a shared $100 account at the same millisecond:
- Core 1 reads the balance as $100 and calculates a new balance of $75.
- Simultaneously, Core 2 reads the balance as $100 — before Core 1 finishes saving its update — and also calculates $75.
- Both cores write $75 back to the database.
Because nothing regulates the overlap, Core 2 silently overwrites Core 1's work. The system processed $50 in withdrawals, but the database reflects only a single $25 deduction — a lost update, and a corrupted state.
Concurrency Control in Processors
But, do processors have any concurrency control?
Yes — at the operating-system level. When multiple instruction streams contend for shared memory, the OS relies on semaphores (signaling primitives that track when a resource is available) and mutexes (mutual-exclusion locks ensuring only one thread holds a lock at a time) to guard critical sections and keep threads from corrupting each other's work.
So how does an 8-core processor execute, say, 16 programs at once? It can't — only 8 instruction streams truly run in parallel at any instant. The operating system rapidly rotates each core through its assigned programs every few milliseconds (time-slicing), so all 16 appear to run side-by-side. And how much each program gets done inside its slice is manifested as the processor's clock speed: the billions of cycles per second (GHz) pacing each core's fetch–decode–execute loop. Time-slicing decides who executes; clock speed decides how much.
But none of this helps a database. A database is just an application running on top of this multi-core infrastructure. Semaphores and mutexes protect memory within one program — they say nothing about transaction-level rules like "no transaction may read another's uncommitted writes." Locking a mutex for the entire duration of a transaction would be correct but would collapse throughput back to a single slow queue. To run queries concurrently and keep them correct, the database needs its own coordination layer: concurrency control.
How Concurrency Control Solves This
The 2 core concepts to grok:
Isolation
- What it means: isolation guarantees each transaction executes as if it is the only transaction running on the database system at that time.
- What it prevents: while a transaction is running, it cannot see temporary, incomplete, or uncommitted reads and writes made by other simultaneous transactions.
- Why it matters: isolation provides a vastly simpler programming model. Instead of requiring application code to handle race conditions or intermediate database states, developers write logic assuming their transaction runs in total isolation.
Correctness (Serializability)
- What it means: serializability is the formal criteria databases use to define correctness for concurrent execution. An interleaved schedule of operations is serializable if the final state of the database is identical to the outcome of executing those same transactions one after another in a serial order.
- Why interleaving is allowed: the database doesn't enforce a single-threaded queue where everyone waits in line. It freely interleaves read and write operations across CPU cores to maximize parallelism and hardware efficiency — as long as the end result matches a valid serial outcome.
- How databases verify it (conflict serializability): in practice, systems determine correctness by tracking conflicting operations (read-write, write-read, or write-write on the same data item) across transactions. The database constructs a dependency graph (precedence graph); if the graph contains no cycles, the execution is proven conflict serializable — and therefore correct.
But What About ACID?
But, what about the ACID properties of databases — and are they even related?
Yes: ACID is the formalization of exactly the isolation and correctness we just described. The relationship runs one direction — ACID is the specification (the safety criteria, the goals), while concurrency control and recovery are the engines built to meet those standards.
The Division of Responsibilities
-
Isolation (I) → handled by concurrency control.
- Goal: make concurrent operations feel as if they are running one at a time.
- Mechanism: concurrency control algorithms (locking schemes like Two-Phase Locking, or optimistic schemes like Optimistic Concurrency Control) manage how operations interleave so transactions never interfere with each other.
-
Consistency (C) → handled by concurrency control + application rules.
- Goal: ensure the database moves from one valid state to another without violating business logic or constraints.
- Mechanism: concurrency control guarantees interleaving never creates invalid states — like the lost update or a negative bank balance from our earlier example.
-
Atomicity (A) & Durability (D) → handled by logging & recovery.
- Goal: all-or-nothing execution, with committed data surviving crashes.
- Mechanism: Write-Ahead Logging records every action to disk first, so the system can undo aborted transactions or redo lost work after a crash.
Mapping Our Two Concepts to ACID
- Isolation is the I in ACID: even when hundreds of queries run concurrently across cores, each transaction feels like the only thing running.
- Correctness spans the C: consistency ensures business rules hold (balance ), while serializability is the mathematical test proving the interleaved execution matches a safe serial order.
ACID defines what a reliable transaction system must guarantee — the goal line of Isolation, Correctness, Atomicity, and Durability. Concurrency control algorithms (locks, conflict graphs) are the how: the machinery built to reach that goal line without slowing the machine down. In short, concurrency control is the means by which databases achieve the ACID guarantees — the I and the C above all.
How Can We Achieve ACID?
Each letter of the contract has its own machinery, and we've now covered the techniques for all four:
- Atomicity — all-or-nothing execution. Two classic techniques: Shadow Paging, where uncommitted changes live on copied pages and an atomic pointer flip makes the whole transaction live at once, and Write-Ahead Logging, where every change is recorded sequentially on disk first so a crash can be undone or replayed.
- Isolation — transactions that feel alone. Two families of protocols: the pessimistic Two-Phase Locking (lock everything before touching it, release in strict phases) and the optimistic Optimistic Concurrency Control (run freely in a private workspace, validate at commit).
- Consistency — only valid states. Enforced by the same isolation machinery preventing illegal interleavings — the exact races cataloged in Concurrency Anomalies — combined with application-level constraints.
- Durability — committed data survives crashes. Handled by the recovery side of the house: the WAL records written ahead of every change, flushed before the commit is acknowledged.
And there's a final twist worth holding onto: the isolation engines themselves split on where they keep their copies — in transient private memory (OCC's scratchpads) or as real physical rows on disk. That distinction is exactly what Multi-Version Concurrency Control explores.
Conclusion
We started with a processor blindly executing one instruction after another, and an operating system that multiplies that one core into an illusion of many programs through time-slicing, semaphores, and mutexes. That machinery is real concurrency control — but only for memory inside a single program. A database is a different beast: an application whose entire purpose is to let many independent users read and write the same shared data at the same time. Without coordination, cores interleave raw reads and writes and produce lost updates — $50 leaves the account, the ledger only records $25.
Concurrency control is the database's answer: a transaction-level coordination layer that grants isolation (each transaction behaves as if it runs alone) and correctness (every interleaving provably matches some serial order, verified through conflict-free dependency graphs). These are exactly the I and C of ACID — the specification of what a reliable database must guarantee — while atomicity and durability are handled by its sibling engine, logging and recovery.
The full stack, end to end: a processor executes; the OS parallelizes; the database must make that parallelism safe — and ACID is the contract it signs to do so.
Related reads
- Concurrency Anomalies — the specific races that appear when this coordination is missing
- Two-Phase Locking — the classic pessimistic algorithm that enforces the I
- Optimistic Concurrency Control — the lock-free counterpart for low-contention workloads
- Shadow Paging — how the A in ACID is delivered without a log