Introduction
To understand phantom writes and write skew, we’ll play a scenario among different bank accounts. Say Trump and Melanie own three accounts between themselves. One of the accounts is a joint account, while the other two are individual accounts. Both Trump and Melanie have setup automated transfers that move $100 from the joint account to their individual account at the end of the month.
Consider the following sequence of events
Trump starts a transfer of $100 from the joint account to his individual account. The application code looks-up the current balance of $100 and deems the transfer can be made and proceeds.
Just after Trump’s transaction reads the joint account balance but before it can update the new balance to $0, Melanie initiates a transaction to move $100 into her individual account. Melanie’s transaction, too, reads in the joint account balance as $100.
At this point there are different outcomes possible, let’s examine each:
Trump’s transaction updates his individual account balance and then the joint account balance to zero but doesn’t commit yet.
Melanie’s transaction updates her individual account balance and then overwrites the joint account balance to zero too.
Trump’s transaction commits.
Melanie’s transaction commits.
In the above sequence, the write by Melanie’s transaction to the joint account balance is a dirty write since Trump’s transaction didn’t commit when Melanie’s transaction updates the joint account’s balance.
Get hands-on with 1400+ tech skills courses.