dirty read: Reading data another transaction has written but NOT committed — it might be rolled back, so you read a value that never existed. A dirty read happens when one transaction reads data another transaction has changed but not committed yet. If that other transaction rolls back, the first one has seen a value that officially never existed.
Imagine one process lowers a stock count but then fails and rolls back. A second process that read the lowered number in between may have told a customer the product is sold out.
What should you keep in mind with dirty read?
Dirty reads only happen at the lowest isolation level, READ UNCOMMITTED. MySQL defaults to REPEATABLE READ and PostgreSQL to READ COMMITTED, both of which prevent them. So you mainly need to know about dirty reads when someone lowers the isolation level for speed. That trade-off is rarely worth it for data that drives decisions.
What does an example of dirty read look like?
-- T1 updates row, T2 reads it, T1 rolls back -- T2 saw a phantom value
Use when code runs things at the same time - threads, async/await, queues and workers, parallel requests, cron jobs, webhooks that retry - or when a bug only happens "sometimes" or under load. Covers race conditions, deadlocks, mutexes/locks, atomic operations, idempotency, message queues and backpressure, with Laravel and database examples.
Master SQL query optimization, indexing strategies, and EXPLAIN analysis to dramatically improve database performance and eliminate slow queries. Use when debugging slow queries, designing database schemas, or optimizing application performance.