liveBook · Manning

Lost update anomaly

As explained in The Coder Cafe

A lost update is a concurrency anomaly in which one transaction's write overwrites another transaction's write based on an earlier shared value.

A lost update occurs when two transactions read the same value, calculate different updates, and only one write survives. The discarded write can leave shared data incorrect. section 6.9.7

Bank account balance

Alice’s balance starts at $0. T1 adds $100 and T2 adds $200. If both read $0 before writing, T2 may leave a final balance of $200, losing T1’s addition instead of producing the expected $300. section 6.9.7

Snapshot isolation uses a consistent snapshot from the transaction’s start and can detect conflicting writes to the same data, typically rolling one transaction back. Repeatable reads also prevent lost updates, but through a different mechanism involving locks on read data. section 6.9.7

When choosing isolation guarantees:

  • Treat lost updates as a data-correctness risk when concurrent operations are expected to accumulate rather than replace one another. section 6.9.7
  • Compare stronger guarantees such as serializability against their potential performance cost in high-concurrency systems. section 6.9.9

How The Coder Cafe covers it

How deep it goes
Defines the anomaly, traces it through a banking scenario, and explains snapshot-isolation conflict handling.
Examples
Uses concurrent deposits into Alice’s bank account, producing $200 instead of the expected $300.
What you can do after
Evaluate isolation levels for preventing lost updates while balancing consistency guarantees against concurrency performance.
How it connects
Connects lost updates with snapshot isolation, repeatable reads, isolation levels, and serializability.

Also explained in

Compare how 3 books explain lost update anomaly →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of The Coder Cafe. The section links point to the parts of the book it draws on.