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

  1. 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.

  2. 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:

  1. Trump’s transaction updates his individual account balance and then the joint account balance to zero but doesn’t commit yet.

  2. Melanie’s transaction updates her individual account balance and then overwrites the joint account balance to zero too.

  3. Trump’s transaction commits.

  4. 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 1200+ tech skills courses.