The study of transactions — atomicity, consistency, isolation, durability — rendered in watercolor.
BEGIN TRANSACTION;
All or nothing. A transaction is an indivisible unit of work — either every operation within it completes successfully, or none of them take effect. There is no partial execution, no half-committed state floating in the void between intention and completion.
all three pass, or the slate is wiped clean
CHECK (balance >= 0)
A transaction carries the database from one valid state to another. Constraints, triggers, and invariants form a contract that the data must honor — before, during, and after every operation. The system never rests in an invalid configuration.
from one truth to another — no lies in between
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
Concurrent transactions execute as if they were serial — each one unaware of the others' intermediate states. The illusion of solitude in a crowded system. No dirty reads, no phantom rows, no lost updates contaminating the result.
each transaction paints on its own sheet of glass
COMMIT; -- written to disk
Once committed, the transaction's effects survive any subsequent failure — power loss, crash, disk corruption. The data persists. The promise of COMMIT is absolute: what is written shall not be unwritten by mere hardware misfortune.
ink that cannot be washed away
Every transaction follows a lifecycle: birth (BEGIN), work (read/write operations), and resolution (COMMIT or ROLLBACK). Between birth and resolution lies a liminal space where changes exist in potential — visible to the transaction itself but invisible to others, held in suspension like pigment floating in wet wash before it settles into the paper fiber.
begin, work, resolve — the rhythm of every reliable system
MVCC — Multi-Version Concurrency Control
Rather than locking rows and forcing transactions to wait, MVCC keeps multiple versions of each row alive simultaneously. Each transaction sees a consistent snapshot — its own private copy of the world, frozen at the moment it began reading.
many painters, one canvas — each seeing their own version of the scene
WAL: intention before action
Before any change touches the data files, the intention is recorded in a sequential log. This simple rule — write the plan before executing it — is the foundation of crash recovery. If the system fails, the log tells the story of what was promised and what was delivered.
first the sketch, then the painting — never the reverse
When a transaction spans multiple nodes, the challenge multiplies. The Two-Phase Commit protocol (2PC) coordinates the decision: first, all participants vote (prepare phase); then, a coordinator announces the verdict (commit or abort). The protocol guarantees agreement but cannot prevent blocking if the coordinator fails mid-decision.
consensus is expensive — but cheaper than inconsistency
Four levels, four trade-offs. READ UNCOMMITTED lets you see uncommitted changes (dirty reads). READ COMMITTED hides uncommitted data. REPEATABLE READ freezes your view of read rows. SERIALIZABLE provides the illusion of sequential execution — at the cost of potential aborts.
more isolation, less throughput — choose wisely
In a distributed system, you can have at most two of three: Consistency, Availability, and Partition tolerance. Since network partitions are inevitable, the real choice is between consistency and availability during failure. CP systems refuse to answer rather than risk stale data. AP systems answer but might be wrong.
you cannot paint with all the colors at once