System Design
16. Performance EngineeringAnimated
Deadlock Prevention
Avoid circular waits.
The idea
Acquire locks in a fixed order, use timeouts, or avoid holding multiple locks.
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
- 1Define a global lock order
- 2Acquire in that order
- 3Use timeouts
- 4Detect and retry
Where it is used
Concurrent code.
Watch out for
Order violations appear in rare paths.