Read-Modify-Write
Last Updated on Feb 17, 2021
Applications generally adopt the Read-Modify-Write cycle to update values in the database.
The process starts with the application reading the existing, committed value from the database and loading it into memory. The value is then manipulated per the requested change, in accordance with any business rules associated with the modification. The changed value is lastly written back into the database to be committed.
While the Read-Modify-Write cycle is easy to code, it exposes the application to the risk of Lost Updates. If two transactions were to concurrently write to the same object or row, the second transaction may overwrite the value written by the first transaction.
Related:
- Lost Updates
- Atomic Write operations prevent Lost Updates
- Atomic Writes
- Explicit Locks
- Applications can use Explicit Locks to prevent Lost Updates
- Databases that automatically detect lost updates simplify application code
- Databases without transaction support can avoid lost updates with compare-and-set operations
- Phantom