lost update

A concurrency bug where two sessions read the same value, both write a result based on it, and the later write silently erases the earlier one.

It silently discards real changes, such as a sale or a payment.

In more detail

Two sessions each read stock 5, each sell one and write 4, and one sale vanishes. Fix it by computing the change in the database with a conditional write, such as SET stock = stock - 1 WHERE stock >= 1, or with a stricter isolation level.

Related terms

Taught in

References