AlgoViz

ACID: atomicity and durability

medium 26 min

A transaction turns several changes into one: all of them happen or none do, and once committed they survive a crash.

Chapter mnemonic

ACID transaction guarantees

Two stamps, balanced books, a private booth, a fireproof receipt.

A committed transfer disappears after a restart. Which guarantee failed?

Durability. A committed result should survive a crash.

Remember it

The few things worth knowing cold, and how to make them stick.

Memory hook

Log first, data later.

Two friends swap stickers. They write the swap in a notebook, move the stickers, then tick it. No tick means put everything back. A tick means the swap stands, whatever the wind does.

Cheat sheet

A
all or nothing
C
rules always valid
I
no interference
D
survives crashes
COMMIT
make it permanent
ROLLBACK
undo all of it
Flush 5 ms, alone
200 commits/s
Two systems
outbox and safe repeats

Spot it when you see

  • Two rows must change together.
  • Money, stock or seats.
  • A retry must be safe.
  • Data and message must both exist.

Tricks that stick

  • The tick in the notebook is the COMMIT record.
  • Before the tick undo, after the tick redo.
  • Atomic is about failure, isolated is about others.

Do not forget

  • Calling a service inside a transaction.
  • Ignoring the row count.
  • Turning off the flush.
  • Long transactions.
  • Expecting one transaction to cover two systems.