Chapter 7: Transactions
Summary: This chapter explores transactions as an abstraction layer that simplifies error handling and concurrency control in databases. It details the ACID guarantees and various isolation levels used to prevent race conditions.
Sources: chapter7
Last updated: 2026-04-17
Key Concepts
The Meaning of ACID
Transactions are often described by the acid acronym:
- Atomicity: The ability to abort a transaction on error and have all its writes discarded.
- Consistency: The requirement that a database must always be in a “good state” (application-defined).
- Isolation: Ensuring that concurrently running transactions do not interfere with each other.
- Durability: The promise that once a transaction has committed, its data will not be lost.
Weak Isolation Levels
Due to the performance cost of full serializability, many databases use weaker isolation levels:
- read-committed: Prevents dirty reads and dirty writes.
- snapshot-isolation: Prevents read skew using multi-version-concurrency-control (MVCC).
Concurrency Anomalies
The chapter identifies several race conditions that can occur:
- lost-updates: Occur when two transactions perform a read-modify-write cycle concurrently.
- write-skew: A generalization of the lost update problem where transactions update different objects based on a shared premise.
- Phantoms: When a write in one transaction changes the result of a search query in another.
Serializability
The strongest isolation level, which guarantees that the result of concurrent transactions is the same as if they had run one at a time. Methods include:
- Actual Serial Execution: Running transactions in a single thread.
- two-phase-locking: A pessimistic concurrency control mechanism.
- serializable-snapshot-isolation: An optimistic concurrency control mechanism.