4.4.16 · D1Databases

Foundations — Transactions — ACID properties (each one in detail)

2,194 words10 min readBack to topic

Before we can talk about atomicity, redo logs, or isolation levels, we must earn every word the parent note used. This page is a dictionary you build, bottom to top — no term appears until the ones beneath it are solid.


0. The stage: what is a "database" here?

Picture a spreadsheet with two columns, id and bal (short for balance), and two rows: Alice and Bob. That single picture is enough to carry the whole ACID story.

Figure — Transactions — ACID properties (each one in detail)

Why we need it: every ACID example ("move ₹100 from Alice to Bob") is just changing the value inside cells of this grid. If you can see the grid, its rows, columns, and cells, you can see every anomaly later.


1. Operation: the smallest move

Why we need it: ACID never argues about single operations — those are trivially safe. The drama begins when we group several operations. So "operation" is the atom; "transaction" is the molecule.

The parent writes these as SQL:

UPDATE acct SET bal = bal - 100 WHERE id = 'Alice';

Read that as: "in the acct table, in the row where id equals 'Alice', replace the bal cell with its old value minus 100." The := symbol the parent uses in examples (Alice.bal := 400) just means "gets assigned the value" — the arrow that overwrites a cell. It is not the = of "is equal to"; it is "becomes".


2. Transaction, its brackets, and Atomicity

Picture a real cardboard box you place around a few operations. Nothing inside is "real" until you seal it (COMMIT). At any moment before sealing you may burn the box (ROLLBACK).

Figure — Transactions — ACID properties (each one in detail)

Why we need it: the entire promise of ACID starts with "the box is indivisible." Without a beginning and an end, there is no "unit of work" to protect. COMMIT is the exact instant durability starts to apply; before it, nothing is guaranteed.


3. State, valid state, invariant, and Consistency

Picture states as dots on a map, and edges as legal transactions hopping between them. Some dots are painted green (valid); the red ones (a negative balance) are forbidden — no transaction is allowed to land there.

Figure — Transactions — ACID properties (each one in detail)

Why we need it: Consistency is defined entirely in this language. Without the word invariant you cannot say what "valid" means.


4. Constraint, CHECK, PRIMARY KEY, FOREIGN KEY

  • CHECK (bal >= 0) — the cell rule "balance must be at least zero". The symbol >= means "greater than or equal to".
  • PRIMARY KEY — "this column uniquely names each row; no two rows share an id."
  • FOREIGN KEY — "a value here must point to a real row in another table" (see Database Constraints).

Why we need it: the parent's Consistency example ("subtract → bal := -50 violates the CHECK → rollback") only makes sense once you know a CHECK is a machine-enforced invariant. Constraints are how the DB keeps you on green dots.


5. Durable vs volatile storage, and Durability

Picture two shelves. The top shelf (RAM) is a whiteboard: instant to write, wiped when the lights go out. The bottom shelf (disk) is stone tablets: slow to carve, but permanent.

Why we need it: Durability is entirely about the RAM-vs-disk gap. Databases keep recent changes on the fast whiteboard for speed; the danger is a crash erasing the whiteboard before it was copied to stone. Every trick — WAL, fsync — is about closing that gap safely.


6. The log, undo log, redo log

Two flavours the parent uses:

  • Undo log stores the old value before a change ("Alice.bal was 500"). It answers: "how do I go backwards?" → used by Undo and Redo Logs for ROLLBACK and to erase crashed, uncommitted work (this powers Atomicity).
  • Redo log stores the new value of a committed change ("Bob.bal becomes 300"). It answers: "how do I re-do work that was committed but hadn't reached the data file?" → this powers Durability via Write-Ahead Logging (WAL).
Figure — Transactions — ACID properties (each one in detail)

Why we need it: the parent literally says "Atomicity uses the undo log, Durability uses the redo log." You cannot understand either property without knowing a log is an append-only diary and which direction (backward = undo, forward = redo) each reads.


7. Concurrency, serial order, anomaly, and Isolation

Picture two hands reaching into the same grid at once. If they grab the same cell in a bad order, one hand sees a half-finished number.

Why we need it: the three anomalies (dirty / non-repeatable / phantom read) and the isolation-level table are meaningless until "concurrent", "serial", and "anomaly" are defined. See Concurrency Control, Isolation Levels, Locking and 2PL, and MVCC for the machinery.


How it all feeds the topic

The diagram below is a prerequisite map. Read it like this: each box is a concept from this page; an arrow A --> B means "A must be understood before B" — A feeds into B. Follow the arrows upward and you arrive at the four ACID promises, which all flow into the single "ACID promise" box at the bottom.

Grid row column cell

Operation - one change

Transaction box - BEGIN COMMIT ROLLBACK

State and invariant

Constraint - CHECK PK FK

Consistency C

Atomicity A

Undo log - old value backward

Volatile vs durable and fsync

Redo log and WAL

Durability D

Concurrent and serial order

Anomaly

Isolation I

ACID promise


Equipment checklist

Read the left side, answer before revealing.

What do the four letters of ACID stand for?
Atomicity (all-or-nothing), Consistency (only valid states), Isolation (concurrent txns don't corrupt each other), Durability (committed work survives crashes).
What is a "cell", and what does it hold?
The single square where a row and a column cross; it holds exactly one value.
What does := mean, as opposed to =?
:= means "the cell becomes this value" (assignment / overwrite); = tests whether two things are equal.
What are the three bracket words of a transaction and what does each do?
BEGIN opens the box, COMMIT seals it permanently, ROLLBACK burns it and undoes everything since BEGIN.
Define a "valid state" and an "invariant".
A valid state breaks no rules; an invariant is a rule that must hold in every valid state (e.g. no negative balance).
What is the difference between volatile and durable storage?
Volatile (RAM) is fast but forgotten on power loss; durable (disk/SSD) is slower but survives a crash.
What does fsync guarantee?
That a change is truly written to durable storage before the command returns — the moment a scribble becomes permanent.
Undo log vs redo log — what does each store and which direction is it read?
Undo stores the OLD value, read backward to reverse changes; redo stores the NEW committed value, read forward to re-apply changes.
What is an "anomaly" in the concurrency sense?
A wrong result that can only occur when transactions overlap — impossible under any strictly serial (one-after-another) order.
Which log powers Atomicity and which powers Durability?
Undo log powers Atomicity (erase crashed uncommitted work); redo log powers Durability (re-apply committed work after a crash).