Skip to content
StackDecode
System Design
4. Database FundamentalsAnimated

Database Transactions

A group of operations that succeed or fail together.

The idea

A transaction either commits all changes or rolls them all back, leaving data consistent.

Watch it work

Press play, pause, or step through. Some animations have settings you can change.

CoordinatorParticipant AParticipant BPREPARE
  • current message
  • earlier
  • failure or attack

Phase 1: the coordinator asks everyone if they can commit.

step:
1/7
from:
Coordinator
to:
Participant A
1/7

Time runs downward. Solid arrows are requests, dashed arrows are replies.

Step by step

  1. 1Begin the transaction
  2. 2Run several statements
  3. 3Commit if all succeed
  4. 4Roll back on any error

Where it is used

Transfers, orders, bookings.

Watch out for

Long transactions hold locks and hurt concurrency.

Related