System Design
16. Performance EngineeringAnimated
Race Conditions
Results depend on timing.
The idea
Two operations touch shared data without coordination and the outcome varies.
Watch it work
Press play, pause, or step through. Some animations have settings you can change.
- current message
- earlier
- failure or attack
Txn 1 changes a value but has not committed.
- step:
- 1/5
- from:
- Txn 1
- to:
- Database
1/5
Time runs downward. Solid arrows are requests, dashed arrows are replies.
Step by step
- 1Two threads read the value
- 2Both modify it
- 3Both write back
- 4One update is lost
Where it is used
Concurrent code.
Watch out for
Use locks, atomics or message passing.