Concurrency Control
Trace locking, optimistic validation, MVCC, and HTTP preconditions, with an example showing the scope of a row-version check.
· Last updated: 2026-11-07 · 8 min read
Overview
Concurrency control sets the rules for how overlapping operations may read and mutate shared state. That overlap happens both when multiple CPU cores execute instructions at the exact same instant and when one task pauses for disk or network I/O while another task steps in.
Picture two editors, A and B, opening the same article. Editor A saves a revision first; a moment later, B saves an edit built on the original text and wipes out A's work completely. Inventory counts and seat reservations fail the exact same way.
Three questions come first. What counts as one unit of work, which state is shared, and which final outcomes are legal? An atomic CPU instruction on one integer, a version check on a single row, and full serializability across a multi-table transaction guard very different scopes.
Whereas OS mutexes and language-level atomics guard in-memory variables, database concurrency control coordinates multi-item transactions across crash recovery and isolation using locks, optimistic validation, and multiversion concurrency control (MVCC).
Timeline
1976: Eswaran, Gray, Lorie, and Traiger defined transactions, consistency, and schedules and analyzed their relationship with two-phase locking. Their paper also distinguished physical records from predicate-defined data sets.1
1981: Kung and Robinson proposed optimistic methods that let work proceed before checking conflicts in On Optimistic Methods for Concurrency Control.2
1983: Philip A. Bernstein and Nathan Goodman formalized the serializability theory of multiversion schedules and unified multiversion algorithms in Multiversion Concurrency Control, Theory and Algorithms.3
1995: Berenson and colleagues analyzed SQL isolation definitions and snapshot isolation, including write skew, in A Critique of ANSI SQL Isolation Levels.4
January 1997: HTTP/1.1's RFC 2068 defined
If-Matchand explained using entity tags to avoid modifying an outdated resource after retrieval.52022: RFC 9110 specified the semantics of the
If-Matchcondition.6
Lock protocols and protection targets (1976)
In their foundational 1976 paper, Eswaran, Gray, Lorie, and Traiger analyzed interleaved reads and writes in a multiuser database. Simply deciding what to lock is not enough; preserving integrity requires a protocol governing when locks are acquired and released, which led to two-phase locking (2PL), where a transaction may never acquire a new lock once it has released any lock.1
Room reservations make the paper's distinction between physical records and predicate-defined sets concrete. Locking the reservation rows currently in a table does nothing to stop a concurrent transaction from inserting a brand-new row that overlaps the same time slot, so concurrency control has to protect the logical predicate space, not just existing bytes.
Optimistic validation (1981)
Why lock upfront if conflicts are rare? In 1981, Kung and Robinson proposed optimistic concurrency control (OCC), splitting execution into read, validation, and write phases so transactions run freely on private copies and check read/write set intersections only at validation time, trading occasional aborts and restarts for freedom from lock-wait queues.2
A web form's row-version check is that optimistic idea shrunk down to a single row: the UPDATE succeeds only if the row's version column still matches what the editor read earlier.
A theory for multiple versions (1983)
Two years later, in 1983, Philip A. Bernstein and Nathan Goodman gave multiversion schedules a unified formal theory. Keeping older row versions around lets readers proceed without blocking behind writers, though storing multiple versions is only half the story: separate isolation rules still have to decide which version a transaction sees and which conflicting schedules must be aborted.3
Real systems mix these techniques freely. An MVCC database still grabs row locks when two writers target the same tuple, and an application's optimistic version check often runs right on top of those internal database write locks.
Snapshot isolation and write skew (1995)
Hal Berenson and colleagues showed in 1995 where snapshot reads fall short of full serializability. Under Snapshot Isolation, two concurrent transactions can read the exact same snapshot, modify different rows, and together break a cross-row business rule, an anomaly known as write skew.4
Stopping a lost update on one row is therefore much narrower than protecting a rule that spans several rows. Every individual row's version check can pass while the multi-row condition the code relied on silently crumbles; beneath labels like locking, validation, or MVCC, the real question is always which combined histories must match a serial execution.
HTTP conditional requests (1997–2022)
The exact same stale-write problem surfaces over HTTP. Introduced in RFC 2068 (1997) and refined in RFC 9110 (2022), HTTP conditional requests let a client attach an If-Match entity-tag precondition so the server rejects an update if the resource changed since it was fetched, provided the backend carries that check all the way down to storage.6
Checking a version at save time spares you from holding a database lock while a human stares at an edit screen for ten minutes. Once a conflict fires, though, deciding whether to retry, reload, or prompt the user to merge belongs to the application.
PostgreSQL row locks and the remaining protection scope
Inside PostgreSQL, SELECT ... FOR UPDATE locks the selected rows against competing updates or deletes until the transaction ends, while leaving ordinary SELECT reads unblocked. If two transactions each hold a row the other wants next, they deadlock.7
And what if a query for existing bookings returns zero rows? Then FOR UPDATE has no row to lock! Guarding an empty slot requires a unique constraint, a lock on a parent resource row, or SERIALIZABLE isolation, all of which PostgreSQL layers on top of its MVCC storage engine.879
Two-phase locking, optimistic validation, multiversion snapshots, and HTTP If-Match headers all tie a write back to the observation that justified it. Always start by asking what scope the contract actually protects.
A row-version condition example
In the PostgreSQL snippet below, the UPDATE statement bakes the observed version directly into its WHERE clause so the second, stale edit is rejected.
CREATE TEMP TABLE posts (
id integer PRIMARY KEY,
body text NOT NULL,
version bigint NOT NULL
);
INSERT INTO posts VALUES (1, 'original', 0);
UPDATE posts
SET body = 'edited by A', version = version + 1
WHERE id = 1 AND version = 0
RETURNING body, version;
UPDATE posts
SET body = 'edited by B', version = version + 1
WHERE id = 1 AND version = 0
RETURNING body, version;
SELECT body, version FROM posts WHERE id = 1;
Update one returns edited by A with version 1; update two matches zero rows and leaves A's text untouched. Under PostgreSQL's default READ COMMITTED level, a concurrent second UPDATE waits for the first commit, re-evaluates its WHERE clause against the new row, and returns zero rows (which caller code must treat as a conflict), whereas REPEATABLE READ and SERIALIZABLE abort the second transaction with a serialization error.
See also
Footnotes
- K. P. Eswaran, J. N. Gray, R. A. Lorie, and I. L. Traiger, “The Notions of Consistency and Predicate Locks in a Database System,” CACM 19(11), 1976, pp.624–633. Paper. ↩
- H. T. Kung and John T. Robinson, “On Optimistic Methods for Concurrency Control,” ACM TODS 6(2), 1981, pp.213–226. Authors' paper. ↩
- Philip A. Bernstein and Nathan Goodman, “Multiversion Concurrency Control—Theory and Algorithms,” ACM TODS 8(4), 1983, pp.465–483. Paper copy. ↩
- Hal Berenson et al., “A Critique of ANSI SQL Isolation Levels,” SIGMOD, 1995, snapshot isolation and A5B. Paper. ↩
- RFC 2068, 1997-01, §14.25 “If-Match.” Historical HTTP/1.1 definition. RFC. ↩
- RFC 9110, §13.1.1 “If-Match.” Standard. ↩
- PostgreSQL 18, §13.3 “Explicit Locking.” Official documentation. ↩
- PostgreSQL 18, §13.4 “Data Consistency Checks at the Application Level”. Official documentation. ↩
- PostgreSQL 18, §13.2 “Transaction Isolation.” Official documentation. ↩