System Design
4. Database FundamentalsAnimated
Deadlocks
Transactions waiting on each other forever.
The idea
Transaction A holds lock 1 and wants 2 while B holds 2 and wants 1. The database detects the cycle and aborts one.
Watch it work
Press play, pause, or step through. Some animations have settings you can change.
- current message
- earlier
- failure or attack
Txn 1 locks row A.
- step:
- 1/6
- from:
- Txn 1
- to:
- Row A
1/6
Time runs downward. Solid arrows are requests, dashed arrows are replies.
Step by step
- 1A locks row 1
- 2B locks row 2
- 3Each requests the other's row
- 4The database aborts one as the victim
Where it is used
Concurrent systems.
Watch out for
Lock rows in a consistent order and retry the victim.