Problem Statement
Which approach helps avoid lost updates in concurrent write scenarios?
Explanation
Attach a version to the aggregate. On update, compare the version; if it changed, reject and let the caller retry with fresh state.
This keeps throughput high under low contention and surfaces conflicts when they matter.
Code Solution
SolutionRead Only
UPDATE orders SET ... WHERE id=? AND version=?; -- if 0 rows affected -> conflict
Practice Sets
This question appears in the following practice sets:
