Two deposits, one balance, and one silently vanishes
transcript
Two sessions add to one balance. One deposit silently vanishes. No error. No crash. Just a lost update.
Session a reads the balance: 70. Session b reads it too: 70. A adds 10 and commits. 80. B adds 20 and commits 90. A's 10 is gone.
Hold the store lock from begin to commit? Then one slow client stops everyone. Instead, each key has a version. Remember the one you read. At commit, has it changed? Then conflict. Nothing changes. The client runs the whole transaction again.
B commits 90. Is balance still the version b read? No. A wrote 80 since. Conflict. B runs again. Reads 80. Adds 20. Commits 100. Both deposits counted. Nothing lost.
The demo: eight threads, 500 increments each. Retry on conflict. Exactly 4,000. Every lost update became a retry instead.
Validate what you read at the outermost commit. No lock while a client thinks. Just a check at the end.
Full breakdown in the lecture.