[Database] Race condition
2 min readJun 1, 2023
A race condition is a type of bug that occurs when multiple transactions (threads or processes) access a shared resource simultaneously, and might cause abnormal behavior.
Dirty read
- A transaction reads data that another transaction hasn’t been committed.
- Occur when an UPDATE, INSERT, DELETE from another transaction.
Read skew (Non-repeatable read)
- A transaction reads inconsistent data because another transaction modify and commit the data during the course of a transaction.
- Occur when an UPDATE from another transaction.
Phantom read
- A transaction reads inconsistent data because another transaction modify and commit the data during the course of a transaction.
- Occur when an INSERT, DELETE from another transaction.
Lost update
- Multiple transactions are trying to modify the same data at the same time, and one of a transaction overwrite modifications from other transactions.
- Occur when an UPDATE from another transaction.
Write skew
- Multiple transactions read the same data first for modifying, but one of a transaction modify the data and commit before other transactions.
- Occur when an UPDATE, INSERT, DELETE from another transaction.