Transactions
Follow transaction history from locking theory through Gray, ACID, snapshot isolation, and PostgreSQL SSI, distinguishing atomicity from isolation.
· Last updated: 2026-11-07 · 9 min read
Overview
A transaction bundles related data operations into a single all-or-nothing unit of work. Think of a bank transfer: if subtracting money from one account and adding it to another commit separately, a crash in the gap between them can make funds vanish or appear twice, whereas wrapping both steps in one transaction guarantees that either both land or neither does.
Several SQL statements can sit inside one database transaction. COMMIT makes their combined changes permanent; ROLLBACK wipes out everything done since the transaction began, though whether a single user click maps to one database transaction or several depends entirely on where the application draws its boundaries.
All-or-nothing recovery solves only half the problem. What happens when two people book the last seat at the same instant, or when two transactions update different rows that together break a business rule? Transactions therefore govern both the unit of crash recovery (atomicity) and how overlapping work is allowed to interleave (isolation).
Far from being just a wrapper around BEGIN and COMMIT, transactions define what counts as a coherent state transition under both crashes and concurrency, with SQL isolation levels and MVCC negotiating the tradeoff between throughput and strict serial behavior.
Timeline
1976: K. P. Eswaran, J. N. Gray, R. A. Lorie, and I. L. Traiger formalized the relationship among transactions, consistency, schedules, and locks in The Notions of Consistency and Predicate Locks in a Database System.1
1981: Jim Gray's The Transaction Concept: Virtues and Limitations described transactions as state transformations with atomicity, consistency, and durability. It organized existing concepts and implementations while discussing unresolved problems such as subtransactions and long-lived work.2
1983: Theo Härder and Andreas Reuter's Principles of Transaction-Oriented Database Recovery provided a common framework for comparing recovery techniques and grouped atomicity, consistency, isolation, and durability under ACID.3
1995: Hal Berenson and colleagues analyzed ambiguities and omitted cases in SQL isolation definitions, including snapshot isolation, in A Critique of ANSI SQL Isolation Levels.4
2012: Dan R. K. Ports and Kevin Grittner published the design and implementation of Serializable Snapshot Isolation (SSI) in PostgreSQL 9.1.5
Shared data and serializability (1976)
Once multiple users touch shared data, steps that look flawless in isolation can produce corrupt results together. Reading stock and subtracting one is fine on its own, yet if another transaction slips its read and write into the middle, one of those updates gets lost.
In 1976, Eswaran, Gray, Lorie, and Traiger connected shared-data consistency directly to execution schedules, proving which locking protocols force interleaved transactions to produce the exact same outcome as running them one after another in series.1 Just as importantly, they showed that locking existing physical records is not enough when a query depends on a predicate condition, new phantom rows matching that condition must be blocked too, framing a transaction as a logical unit of consistency rather than a single statement.
Serializability is that gold standard: the net effect of concurrent transactions must match some serial order. Real databases overlap execution for speed and enforce serializability by making conflicting operations wait or by aborting one of them.
State transformations and recovery boundaries (1981)
Where does rollback stop working? Jim Gray's 1981 paper answered that by splitting actions into three buckets: unprotected actions (like scratch files) that need no recovery after an abort, protected actions (like database writes) that can and must be undone or redone, and real actions (like an ATM dispensing cash) that cannot be taken back once they happen and must therefore be held until commit.2 That boundary explains why calling an external payment API or publishing to a message broker inside a database transaction cannot be undone by a simple local ROLLBACK.
When a crashed server boots back up, recovery boils down to two blunt questions: which writes belonged to the same unit of work, and which units crossed the commit line? Transaction boundaries and commit log records serve both as runtime control flow and as the durable evidence recovery relies on.
ACID and a common language for recovery (1983)
Property | Problem addressed |
|---|---|
Atomicity | Avoid committing only part of an operation; establish completion or cancellation of the unit |
Consistency | Require transformations to preserve declared integrity and business rules |
Isolation | Control observations and interference among overlapping transactions |
Durability | Preserve committed effects under the storage and recovery contract |
- Property
Atomicity
- Problem addressed
Avoid committing only part of an operation; establish completion or cancellation of the unit
- Property
Consistency
- Problem addressed
Require transformations to preserve declared integrity and business rules
- Property
Isolation
- Problem addressed
Control observations and interference among overlapping transactions
- Property
Durability
- Problem addressed
Preserve committed effects under the storage and recovery contract
In 1983, Theo Härder and Andreas Reuter gave recovery engineering its shared vocabulary, coining ACID for atomicity, consistency, isolation, and durability while comparing logging, checkpointing, and buffer-management schemes under one roof, with Write-Ahead Logging (WAL) forcing undo/redo records onto stable storage before dirty data pages are ever overwritten.36 Even so, the database only enforces constraints it knows about: if application code calculates the wrong price, the engine will faithfully commit the mistake.
Vendor-specific crash-recovery tricks finally had a common yardstick.
SQL isolation levels and write skew (1995)
On the isolation side, Hal Berenson and colleagues showed in 1995 why the ANSI SQL anomaly list, dirty reads, nonrepeatable reads, and phantoms, was too weak to define isolation levels cleanly.4 In particular, Snapshot Isolation hands each transaction a stable view of committed data and blocks all three classic anomalies, yet still permits write skew: two transactions read the same snapshot, update disjoint rows, and together violate an invariant across those rows, proving that “neither transaction overwrote the other's row” does not equal serializability.
Implementing serializability over snapshots (2012)
Can a database keep non-blocking snapshot reads and still guarantee full serializability? Dan R. K. Ports and Kevin Grittner's 2012 paper on Serializable Snapshot Isolation (SSI) in PostgreSQL 9.1 showed how: in the classic on-call doctor scenario, where two doctors both see two doctors on duty and each updates their own row to sign off, plain snapshot isolation lets both commits through and leaves zero doctors on call, whereas SSI watches for dangerous read/write dependency structures across snapshots and aborts one transaction, accepting occasional false-positive aborts to keep tracking fast.5
MVCC stores multiple row versions; the active isolation level decides which versions a query may see and which write patterns get rejected. Even in PostgreSQL 18, Read Committed, Repeatable Read, and Serializable behave quite differently under contention, and any transaction aborted with a serialization failure must be retried as a whole unit by the caller.7
Business operations across services
Stretch a business workflow across several services and a single database transaction no longer covers the whole job. Decrementing stock and inserting an order in the same database can share a local commit, whereas charging a credit card or publishing an event to another service crosses into territory local rollback cannot reach.
Architectures bridge that gap with distributed two-phase commit, multi-step sagas with compensating actions, or a transactional outbox that writes the business change and the outgoing event into the same local database table. All three patterns revisit Gray's 1981 boundary, starting from a simple question: how far does one database's rollback actually reach?
Example: atomicity and rollback
In the PostgreSQL script below, stock deduction and order creation share a transaction block, so issuing ROLLBACK cancels both writes as a unit.
CREATE TEMP TABLE stock (id integer PRIMARY KEY, quantity integer NOT NULL);
CREATE TEMP TABLE orders (id integer PRIMARY KEY, item_id integer NOT NULL);
INSERT INTO stock VALUES (1, 1);
BEGIN;
UPDATE stock SET quantity = quantity - 1 WHERE id = 1;
INSERT INTO orders VALUES (100, 1);
ROLLBACK;
SELECT quantity FROM stock WHERE id = 1;
SELECT count(*) FROM orders;
Run the script through psql and the final query reports stock 1 and 0 orders. Both writes vanished together; swapping ROLLBACK for COMMIT at the end commits both.
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. Institutional bibliography and abstract. ↩
- Jim Gray, “The Transaction Concept: Virtues and Limitations,” VLDB, 1981. Author's paper. ↩
- Theo Härder and Andreas Reuter, “Principles of Transaction-Oriented Database Recovery,” ACM Computing Surveys 15(4), 1983, pp.287–317. Paper copy. ↩
- Hal Berenson et al., “A Critique of ANSI SQL Isolation Levels,” SIGMOD, 1995, §4.2 and A5B. Research paper. ↩
- Dan R. K. Ports and Kevin Grittner, “Serializable Snapshot Isolation in PostgreSQL,” PVLDB 5(12), 2012, pp.1850–1861, §1–2.1.1 and §3.3. Publisher's paper. ↩
- PostgreSQL 18, §28.3 “Write-Ahead Logging (WAL)”. Official documentation. Explains flushing the relevant WAL records to permanent storage before writing data files. ↩
- PostgreSQL 18, §13.2 “Transaction Isolation.” Official documentation. ↩