I built a simple wallet system like GPay / PhonePe.
Users can:
Store money
Send money
View transactions
Here I focused on Durability
Because once money is sent, it should never be lost.
CREATE TABLE accounts (
id SERIAL PRIMARY KEY,
name TEXT NOT NULL,
balance INT NOT NULL CHECK (balance >= 0),
last_updated TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
INSERT INTO accounts (name, balance)
VALUES
('Alice', 1000),
('Bob', 500);
Transfer Money
BEGIN;
UPDATE accounts
SET balance = balance - 200
WHERE name = 'Alice';
UPDATE accounts
SET balance = balance + 200
WHERE name = 'Bob';
COMMIT;
After Restart
I restarted the DB and checked again:
SELECT * FROM accounts;
After COMMIT, data is saved permanently Even if system crashes, data is not lost
If crash happens:
Before commit the changes gone After commit the changes safe
Top comments (0)