Lost Updates
Summary: A concurrency anomaly that occurs when two transactions concurrently perform a read-modify-write cycle on the same data.
Sources: chapter7
Last updated: 2026-04-17
The lost update problem can occur if an application reads some value from the database, modifies it, and writes back the modified value (a read-modify-write cycle). If two transactions do this concurrently, one of the modifications can be lost (source: chapter7).
Examples
- Incrementing a counter.
- Updating an account balance.
- Making a local change to a complex value (e.g., adding an element to a list in a JSON document).
Solutions
- Atomic Write Operations: Many databases provide atomic update operations (e.g.,
UPDATE counters SET value = value + 1 WHERE key = 'foo'). - Explicit Locking: The application can explicitly lock objects that are going to be updated (e.g., using
SELECT ... FOR UPDATE). - Automatic Lost Update Detection: The database can detect when a lost update has occurred and abort the offending transaction.
- Compare-and-set: An operation that only allows an update to happen if the value has not changed since it was last read.