Refer to this article written by me: Ensuring Consistent Transactions I've tried to showcase how atomicity in transactions actually take place.
We're taking an example of 2 accounts (id = 3 and 4). A transaction takes place where money is supposed to get deducted from account id = 3 and should be added to account id = 4. If this wasn't atomic, this transaction might fail when money is deducted from account id = 3 before adding the same to other account.
Let's see a happy scenario.
- Initially these are the account balances.
- After the transaction happens successfully:
Now, when an error occur in between the transaction - Let's say account 4 does not exist anymore: