Databases & Data Storage
Dirty Read
Definition
A dirty read is a situation where a transaction reads data that has been written by another transaction that has not yet been committed. If the first transaction is rolled back, the data read by the second transaction becomes invalid.
Why It Matters
Dirty reads can lead to applications making decisions based on incorrect, temporary data. Preventing them is a key goal of database transaction isolation.
Contextual Example
Transaction A updates a product's price from $10 to $15. Before Transaction A commits, Transaction B reads the price as $15. If Transaction A then rolls back, Transaction B has acted on a price that never officially existed.
Common Misunderstandings
- This is one of several "read phenomena" that transaction isolation levels are designed to prevent.
- The lowest isolation level, `READ UNCOMMITTED`, allows dirty reads. All higher levels prevent it.