
CA 34 – Atomicity – Reliable Wallet Transfer System (ACID)
This exercise was about understanding Atomicity in databases using a wallet transfer system like PhonePe or GPay. The main idea is when money is transferred from one account to another, both debit and credit must happen together. If one fails, everything should rollback. That is what Atomicity means either everything happens or nothing happens. First we created the accounts table and inserted dummy data like Alice and Bob with balances. Before doing any transfer, I checked the balances. SELECT * FROM accounts; Suppose Alice sends 200 to Bob. We must do this inside a transaction block. Correct Transaction (Atomic Transfer): BEGIN; UPDATE accounts SET balance = balance - 200 WHERE name = 'Alice'; UPDATE accounts SET balance = balance + 200 WHERE name = 'Bob'; COMMIT; Here what happens is first Alice balance reduces, then Bob balance increases, and finally COMMIT saves the changes permanently. If we check balances after commit: Alice = 800 Bob = 700 So transfer successful. Then we tested
Continue reading on Dev.to Tutorial
Opens in a new tab



