
CA 26 - Consistency
Ensuring Data Consistency in a Digital Wallet System In this experiment, I focused on understanding how a database maintains data consistency , especially in a financial system like a digital wallet (PhonePe/GPay type). The key goal was to ensure that invalid states — such as negative account balances — are never allowed. Initial Setup I used the same accounts table with a constraint to prevent negative balances: ```sql id="a1b2c3" 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); To verify: ```sql id="d4e5f6" SELECT * FROM accounts; Initial balances: Alice → 1000 Bob → 500 Attempt 1: Deduct More Than Available Balance I tried to deduct more money than Alice has: ```sql id="g7h8i9" UPDATE accounts SET balance = balance - 1500 WHERE name = 'Alice'; --- ### Observation PostgreSQL throws an error like: ``
Continue reading on Dev.to
Opens in a new tab




