The problem
We are transferring money between accounts
After transaction is committed data should not be lost
Even if system crashes data must remain correct
Initial Data
Alice has 1000
Bob has 500
Transaction Flow
Transfer 200 from Alice to Bob
Step 1
Start transaction
Step 2
Deduct 200 from Alice
Step 3
Add 200 to Bob
Step 4
Commit transaction
After Commit
Alice balance becomes 800
Bob balance becomes 700
Changes are saved in database
After System Restart
Reconnect to database
Check balances again
Alice still has 800
Bob still has 700
Changes are not lost
Database follows durability property
Once transaction is committed data is permanently stored
Even if system crashes
Committed data remains
Failure before commit
Transaction is not completed
Changes are rolled back
Final state
Alice 1000
Bob 500
Failure after commit
Transaction already saved
Data remains unchanged
Final state
Alice 800
Bob 700
Commit makes data permanent
Database ensures committed data is never lost
Top comments (0)