Atomicity – Reliable Wallet Transfer with ACID (Simple)
When I learned about ACID properties, the one I understood first was Atomicity. It is very simple — it means all or nothing.
I can explain this using a wallet transfer example.
What I am trying to do
Let’s say:
Wallet A has ₹1000
Wallet B has ₹500
I want to send ₹200
So internally, two things should happen:
₹200 should be deducted from Wallet A
₹200 should be added to Wallet B
The Problem
If only one step happens, it becomes a big issue.
Example:
Money is deducted from A
But not added to B
Now ₹200 is lost. This is not acceptable in real applications.
How I Solve This
To avoid this, I use a database transaction.
BEGIN;
UPDATE wallet SET balance = balance - 200 WHERE id = 'A';
UPDATE wallet SET balance = balance + 200 WHERE id = 'B';
COMMIT;
If everything works fine → COMMIT
If any error happens in between →
ROLLBACK;
This cancels all changes and keeps the data safe.
Why Atomicity is Important
No money loss
No partial updates
System stays correct
Simple Idea
Transfer is one single action, not two separate steps
Conclusion
When I design a wallet system, I always use Atomicity to make it reliable.
Because in payments, even a small mistake can cause big problems.
So I always remember:
Either everything happens or nothing happens.
Top comments (0)