The Four Isolation Levels
Read Uncommitted through Serializable and what each permits.
The Four Isolation Levels is a free SQL Interview Prep lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the SQL Interview Prep learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
The Question Behind the Question
When an interviewer asks "name the four isolation levels", the real test is whether you can explain the trade-off: stronger isolation means fewer anomalies but lower concurrency.
The SQL standard defines four levels, ordered from weakest to strongest:
- READ UNCOMMITTED
- READ COMMITTED
- REPEATABLE READ
- SERIALIZABLE
Each level permits or forbids a specific set of read anomalies. This lesson covers the levels; the next covers the anomalies in detail.
Setting the Isolation Level
You set isolation per transaction or per session. The syntax is nearly identical across engines.
If you do not set it, every database has a default. Knowing the defaults is a frequent interview question, so we will cover them at the end.
-- Per transaction (standard SQL)
BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED;
-- ... statements ...
COMMIT;
-- Per session
SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ;Level 1: READ UNCOMMITTED
READ UNCOMMITTED is the weakest level. A transaction can read rows that another transaction has modified but not yet committed. These are called dirty reads.
If that other transaction rolls back, you have read data that never officially existed. This is dangerous for anything that must be correct.
Note: Postgres treats READ UNCOMMITTED the same as READ COMMITTED, so it never actually does dirty reads. SQL Server and MySQL do honor it.
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
BEGIN;
-- may see another transaction's uncommitted (dirty) rows
SELECT balance FROM accounts WHERE id = 1;
COMMIT;Level 2: READ COMMITTED
READ COMMITTED guarantees you only ever read data that has been committed. No dirty reads.
However, each statement sees the latest committed snapshot. If you run the same query twice in one transaction, another committed transaction in between can change the result. That anomaly is a non-repeatable read.
This is the default in Postgres, Oracle, and SQL Server, and it is a sensible balance for most applications.
SET TRANSACTION ISOLATION LEVEL READ COMMITTED;
BEGIN;
SELECT balance FROM accounts WHERE id = 1; -- returns 500
-- another transaction commits an update to id = 1
SELECT balance FROM accounts WHERE id = 1; -- may now return 700
COMMIT;Level 3: REPEATABLE READ
REPEATABLE READ ensures that if you read a row twice in the same transaction, you get the same value both times. It takes a consistent snapshot at the start of the transaction.
It prevents dirty reads and non-repeatable reads. The standard still permits phantom reads: new rows matching your WHERE clause that appear on re-query.
Important: this is the default in MySQL/InnoDB, and InnoDB's implementation also blocks most phantoms via next-key locks.
SET TRANSACTION ISOLATION LEVEL REPEATABLE READ;
BEGIN;
SELECT balance FROM accounts WHERE id = 1; -- 500
-- another transaction commits a change to id = 1
SELECT balance FROM accounts WHERE id = 1; -- still 500 in this txn
COMMIT;Level 4: SERIALIZABLE
SERIALIZABLE is the strictest level. The database guarantees that the result of running transactions concurrently is identical to running them one after another in some serial order.
It prevents dirty reads, non-repeatable reads, and phantoms. The cost: more locking or, in Postgres, serialization-failure aborts that you must retry.
Interview phrasing: "SERIALIZABLE gives the illusion that every transaction ran alone, at the price of reduced concurrency and possible retries."
BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE;
SELECT SUM(balance) FROM accounts;
INSERT INTO audit (total) VALUES (...);
COMMIT; -- may raise a serialization_failure you retryThe Anomaly Matrix
The single most useful thing to memorize is which anomaly each level allows. "Yes" means the anomaly can occur.
- READ UNCOMMITTED: dirty=Yes, non-repeatable=Yes, phantom=Yes
- READ COMMITTED: dirty=No, non-repeatable=Yes, phantom=Yes
- REPEATABLE READ: dirty=No, non-repeatable=No, phantom=Yes (per standard)
- SERIALIZABLE: dirty=No, non-repeatable=No, phantom=No
Each step up forbids one more anomaly. That progression is the whole answer.
Standard vs Real Implementations
A senior-level distinction: the SQL standard defines levels by which anomalies they must prevent, not how. Real engines often prevent more.
- Postgres REPEATABLE READ uses snapshot isolation and blocks phantoms too, though it can still hit write-skew.
- MySQL/InnoDB REPEATABLE READ blocks phantoms with next-key locking.
- Postgres SERIALIZABLE uses SSI (Serializable Snapshot Isolation), aborting on conflict rather than heavy locking.
Mentioning this shows you know the standard is a floor, not the exact behavior.
Default Levels by Engine
Defaults come up constantly. Commit these to memory:
- PostgreSQL: READ COMMITTED
- Oracle: READ COMMITTED (no dirty reads ever)
- SQL Server: READ COMMITTED
- MySQL (InnoDB): REPEATABLE READ
The MySQL outlier is a favorite gotcha. If asked "what is the default isolation level?" always clarify the engine first.
Choosing a Level in Practice
How do you decide? Frame it as risk versus throughput.
- Use READ COMMITTED for typical OLTP; it is fast and avoids dirty reads.
- Use REPEATABLE READ when a transaction reads the same data multiple times and must stay stable (reports, multi-step calculations).
- Use SERIALIZABLE for correctness-critical logic where any anomaly is unacceptable, and design retry logic for aborts.
Almost never use READ UNCOMMITTED in production.
Common Follow-Up Questions
Once you list the levels, interviewers probe with rapid follow-ups. Have crisp answers ready:
- "Which level prevents dirty reads but allows non-repeatable reads?" READ COMMITTED.
- "What is the only anomaly REPEATABLE READ still permits per the standard?" Phantom reads.
- "Why not always use SERIALIZABLE?" It reduces concurrency and can force transaction retries on serialization failures.
- "Does a higher level cost more?" Yes, in locking or in abort-and-retry overhead.
Answering these instantly proves the ladder is internalized, not memorized.
Quick Check
One of these is the most-tested default-level fact.
Recap: Four Levels, One Trade-Off
The four isolation levels form a ladder from weakest to strongest: READ UNCOMMITTED, READ COMMITTED, REPEATABLE READ, SERIALIZABLE. Each step up forbids one more anomaly (dirty, non-repeatable, phantom) at the cost of concurrency.
Remember the defaults (READ COMMITTED everywhere except MySQL's REPEATABLE READ), and note that real engines often prevent more than the standard requires. Next, we examine the three read anomalies these levels are designed to stop.
Frequently asked questions
Is the “The Four Isolation Levels” lesson free?
Yes — the full text of “The Four Isolation Levels” is free to read here on the web, and the SQL Interview Prep course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the SQL Interview Prep course, upgrade to CoddyKit PRO.
What will I learn in “The Four Isolation Levels”?
Read Uncommitted through Serializable and what each permits. You practise SQL Interview Prep with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start SQL Interview Prep?
No prior experience is required. SQL Interview Prep on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “The Four Isolation Levels” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this SQL Interview Prep lesson?
Yes. Every SQL Interview Prep lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- ACID Properties Explained
- The Four Isolation Levels
- Dirty, Non-Repeatable and Phantom Reads
- Deadlocks, Locking and MVCC