InterviewHubPRO
Section Overview
Q9

Question 9 of 60

Part 2: Relational Databases (RDBMS / PostgreSQL / MySQL) (6 - 25)

15%
Databases & System Design•Part 2: Relational Databases (RDBMS / PostgreSQL / MySQL) (6 - 25)

SQL Transaction Isolation Levels:

In Simple Words: Controls how visible uncommitted changes from other transactions are:

  1. Read Uncommitted: Lowest isolation; allows dirty reads.
  2. Read Committed (Default in Postgres): Reads only committed rows.
  3. Repeatable Read (Default in MySQL InnoDB): Guarantees the same row read twice inside a transaction returns identical data.
  4. Serializable: Highest isolation; transactions execute as if run strictly one after another.
sql
-- Setting isolation level for a sensitive financial transaction:
BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE;
SELECT balance FROM accounts WHERE id = 42;
UPDATE accounts SET balance = balance - 500 WHERE id = 42;
COMMIT;