← Back

Concurrency Control Theory in Databases

8 min read

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:

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

Correctness (Serializability)

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

  1. 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.
  2. 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.
  3. 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

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:

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.