retrystorm · Learn · Interview practice · Glossary · Components

Home › Reference › Glossary › Two-phase commit

Two-phase commit

A coordinator asks every database to prepare a change, then tells them all to commit or all to roll back. It blocks if the coordinator fails in between.

Taught in Chapter 31: Transactions and isolation.

More from the same chapter

  • Deadlock: Two transactions each waiting for a lock the other holds. The database aborts one so the other can go on.
  • Dirty read: Reading another transaction's change before it commits, when it may still be rolled back.
  • Fencing token: A version number that grows with each new hold or lock. A write carrying an older one is refused.
  • Hold: A short-lived reservation, such as a seat kept for one buyer for ten minutes, taken in one transaction and freed when it expires.
  • Isolation level: How far a transaction is shielded from the others running at the same time.
  • Lock: A claim a transaction holds on a row until it commits or aborts. Another transaction that needs the row waits for it.
  • Lost update: Two overlapping read-modify-writes on one row, where the second overwrites the first without seeing it.
  • Optimistic concurrency: Taking no lock, and checking at commit that the row is unchanged, restarting when it isn't.
  • Phantom: A row that matches a query appears between two runs of it inside one transaction.
  • Read committed: An isolation level that shows only committed data, as of each read. The usual default, and it still allows lost updates.
  • Saga: A change across several databases made as a series of local transactions, each with a compensation that undoes it if a later step fails.
  • Serializable: An isolation level that behaves as if transactions ran one at a time, by locking or by aborting one of two that conflict.
  • Snapshot isolation: An isolation level that shows the data as it was when the transaction began, and aborts it if it changes a row someone else changed since.
  • Transaction: A group of reads and writes that take effect together or not at all.
  • Write skew: Two transactions each check something the other then changes, so both commit and together break a rule.
About · Contact · Privacy · Terms of use