Database transactions and commit boundaries
medium 4 minDefine the smallest set of changes that must succeed together.
Video lesson · Chapter 1 of 5
Twenty-five credits leave the till
Can a booking use a seat and then disappear?
1:14Reel
Theory
Read or listen first. About 1 min.
What it is
A booking leaves two durable facts behind. A seat is consumed and a reservation exists. The transaction boundary encloses every database write needed to establish that pair.
One booking changes two records
Why it exists
After a crash, recovery must expose a coherent answer to the next buyer. Publishing half of a booking makes the inventory and reservation records disagree.
Words to know
- Atomicity
- A transaction’s changes take effect together or are rolled back together.
How it works
Step through the idea, or press Play.
Begin. A request must consume quota and create a reservation.
Understand it
Worked example
Database transactions and commit boundaries in practice
Creating a reservation also decrements a quota. A crash after the decrement but before insertion leaks quota if the writes commit separately. Put both in one transaction, then acknowledge success after commit.
Related case
A transfer crosses two shards
An allocation moves credits between two accounts on different shards. The coordinator loses its response after asking the participants to commit.
Check the original transaction identity.