
Atomicity - Design a Reliable Wallet Transfer System with ACID Guarantees
In this task, I implemented a simple wallet transfer system to understand the Atomicity property of ACID. Atomicity means that a transaction should either complete fully or not happen at all. There should be no partial updates. First, I created a table called accounts to store user details and balance. CREATE TABLE accounts ( id SERIAL PRIMARY KEY, name TEXT NOT NULL, balance INT NOT NULL CHECK (balance >= 0), last_updated TIMESTAMP DEFAULT CURRENT_TIMESTAMP ); Then I inserted some sample data. INSERT INTO accounts (name, balance) VALUES ('Alice', 1000), ('Bob', 500); To verify the initial state, I checked the table. SELECT * FROM accounts; At this point, Alice had 1000 and Bob had 500. Next, I performed a successful money transfer of 200 from Alice to Bob using a transaction block. BEGIN; UPDATE accounts SET balance = balance - 200, last_updated = CURRENT_TIMESTAMP WHERE id = 1; UPDATE accounts SET balance = balance + 200, last_updated = CURRENT_TIMESTAMP WHERE id = 2; COMMIT; After e
Continue reading on Dev.to
Opens in a new tab




