.NET Architecture & System Design Interview Question #79

What is a dirty read?

Transactions, CQRS, Event Sourcing & Distributed Consistency Mid-Level Intermediate

Quick Interview Answer

A dirty read occurs when one transaction reads data written by another transaction that has not yet committed. If the writer later rolls back, the reader has observed data that never became permanent.

Detailed Explanation

A dirty read occurs when one transaction reads data written by another transaction that has not yet committed. If the writer later rolls back, the reader has observed data that never became permanent.

Isolation levels such as Read Committed prevent dirty reads in typical relational databases.

Code Example

Transaction A: UPDATE Balance = 500
               (not committed)

Transaction B: reads 500

Transaction A: ROLLBACK
// B observed uncommitted data.