AlgoViz

Database transactions and commit boundaries

medium 4 min

Define the smallest set of changes that must succeed together.

Video lesson · Chapter 1 of 5

Twenty-five credits leave the till

0:00 / 3:27

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

Durable recordBeforeAfterFree quotaReservation R71None1NoneAfter recovery, both original values remain.
The quota decrement and the new reservation are pending in one transaction. A crash rolls both changes back.

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.

Step 1 of 3

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.

Follow transfer T17
Move 40 credits with receipt T17Shard A100 creditsT17openedShard B0 creditsStart with 100 credits in total

Check the original transaction identity.

Sources