System Design
5. Advanced Database ArchitectureAnimated
Pessimistic Concurrency Control
Lock first so conflicts cannot happen.
The idea
The transaction takes locks before touching data, blocking others.
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
- 1Acquire locks
- 2Read and modify
- 3Commit
- 4Release locks
Where it is used
High-contention data.
Watch out for
Waiting and deadlocks.