CA 36 – Isolation (ACID)

Published: (March 29, 2026 at 06:36 AM EDT)
1 min read
Source: Dev.to

Source: Dev.to

Scenario

The experiment demonstrates how the Isolation property of ACID works when two sessions try to operate on the same account concurrently.

Steps

Session 1

BEGIN;
UPDATE accounts
-- (no COMMIT yet)

Session 2

SELECT * FROM accounts WHERE name = 'Alice';

Result: The balance still shows 1000, not the uncommitted value (e.g., 200).

UPDATE accounts
-- (this statement blocks, waiting for Session 1 to finish)

Commit in Session 1

COMMIT;

After the commit, Session 2’s blocked UPDATE proceeds, using the newly committed value. The final balance reflects the combined effect of both transactions.

Changing Isolation Levels

READ COMMITTED (default)

SET TRANSACTION ISOLATION LEVEL READ COMMITTED;

Behavior: Same as above—no dirty reads; Session 2 sees only committed data.

SERIALIZABLE

SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;

Behavior: If two transactions conflict, one will abort with an error instead of waiting silently, preventing potential anomalies.

Takeaway

Isolation ensures that concurrent transactions do not interfere with each other’s intermediate states. Even when multiple users attempt to modify the same account simultaneously, the database maintains consistency and prevents data corruption.

0 views
Back to Blog

Related posts

Read more »

CA 40 - Alter Tables

Practice ALTER TABLE Statements 1. Make Email NOT NULL customers sql ALTER TABLE customers MODIFY email VARCHAR100 NOT NULL; Result: email becomes a required f...

Alter Tables

1. Make the email column NOT NULL in customers sql ALTER TABLE customers ALTER COLUMN email SET NOT NULL; 2. Ensure username is unique in users sql ALTER TABLE...