Transaction Isolation Levels Explained with Examples

Read uncommitted, read committed, repeatable read and serializable: what each prevents, and how PostgreSQL, MySQL, SQL Server and Oracle differ.

In this chapter

Isolation levels: how much of other transactions you see

Isolation levels: common questions

What is the default isolation level?

MySQL InnoDB uses REPEATABLE READ. PostgreSQL, SQL Server and Oracle use READ COMMITTED.

Read committed vs repeatable read?

READ COMMITTED takes a new snapshot for every statement. REPEATABLE READ keeps one snapshot for the whole transaction, so re-reading gives the same result.

More on Transactions: isolation

Keep learning

Overview

chapters · transactions, isolation and locks Isolation levels: how much of other transactions you are allowed to see phone sales counted phone sales listed, same transaction errors raised

1. Five levels, one sentence each

An anomaly is a wrong result that only appears when transactions overlap. → anomalies chapter READ UNCOMMITTED Sees uncommitted changes, even ones later rolled back. READ COMMITTED Each statement sees what is committed when it starts. REPEATABLE READ Rows you read keep their value. New rows: not covered. Every statement sees the database as of your snapshot. Same result as running one at a time. Standard: 4 levels Defined by the read anomalies they permit. Snapshot: not standard Most engines offer it, sometimes under another name. Writes have anomalies too: lost update and write skew. → write anomalies · → snapshot reads

2. Which anomalies each level stops

Typical behaviour per level Dirty read Non-repeatable read Lost update Write skew READ UNCOMMITTED READ COMMITTED REPEATABLE READ Phantoms pass lock-based RR You cannot lock a row that does not exist yet. Snapshot ≠ serializable Blocks all read anomalies, still allows write skew. Snapshot stops lost update by aborting the second writer. → the a/b swap

3. Same name, three ways to build it

Pick REPEATABLE READ and switch styles: the phantom cell changes, write skew stays open. Mechanism per level Lock-only engine Snapshot engine READ UNCOMMITTED No read locks Newest version, or acts as READ COMMITTED READ COMMITTED Short read locks Snapshot per statement REPEATABLE READ Read locks held to commit Snapshot per transaction + range locks + range locks, or conflict detection that aborts 🔒 Range locks (pessimistic) Block inserts into what you scanned. You wait. 🔍 Conflict detection (optimistic) Track read/write cycles, abort one. You retry. → lock types · → when a snapshot is taken

4. What the big engines actually do

Same level names, different behaviour. Test the anomaly you care about. Defaults and quirks READ UNCOMMITTED RR phantoms RR lost update Top level write skew READ COMMITTED acts as RC MySQL / InnoDB REPEATABLE READ SQL Server not offered Only RC and SERIALIZABLE, which is really snapshot isolation. → PostgreSQL locks and isolation · → gap locks · → MySQL MVCC

5. Example: a report that contradicts itself

A: report B: new sale phone rows phone: 3 3 (+1 pending) sale committed 4 rows: contradicts! A: report (REPEATABLE READ) one snapshot phone: 4 another phone sale still 4: agrees Fix: the whole report reads one snapshot. READ ONLY Default RR already does this for plain SELECTs.

6. What the stricter levels cost

Add writers, point them at the same rows, and compare how each level pays. Locks make others queue. The engine kills one transaction. An abort you must re-run. No retry loop, no SERIALIZABLE. Hot rows hurt at every level. Run transaction Deadlock / 40001 serialization failure Short random delay Re-run whole transaction

7. Choosing and setting a level

Setting the level Applies to Watch out MySQL: next tx. PG: current tx. SQL Server: rest of session PG: inside the tx, before the first query The tx it opens (PostgreSQL) MySQL: SET TRANSACTION … then START TRANSACTION The tx it opens (standard SQL, PG) Not accepted by MySQL Every later tx on this connection Pools pass it to the next user Quiz: pick the lowest level that is still correct. Often a locking read on the rows that matter beats raising the level. → snapshot reads

Remember

RC → RR → Snapshot → Serializable Now · rows stay · as of start · one at a time. Snapshot allows write skew So it is not serializable. Names lie Reports need one snapshot REPEATABLE READ or higher, or numbers disagree. Always retry Stricter means more waits, deadlocks, retries.

More courses

  • Jobs, linked to lessons — Browse jobs where every requirement links to the chapter that teaches it. See how ready you are, how long the gap takes to close, and which listings look stale.
  • Match a job post to courses — Paste a job post. Each skill is matched to a track here and put in learning order, foundations first.
  • React patterns from open source — Patterns extracted from Material UI, Radix, React Aria, React Hook Form, Redux Toolkit, TanStack, and Next.js — not slides about hooks.
  • System Design — Core concepts first (SQL vs NoSQL, CAP, indexing, replication, sharding), then designs grouped by what carries them: the database, Redis, Kafka, or many services.
  • NestJS: build a real API — One ticket-booking API, built in order: a plain Node server first, then NestJS modules, validation, a real database, and the features real clients lean on.
  • Microservices — Microservice patterns one diagram at a time: how to split a monolith, how services talk, and how data stays consistent without distributed transactions.
  • Kafka — A beginner-to-senior path through event logs, reliable delivery, production operations, and disaster recovery.
  • AI engineering for software engineers — Eight free reads, in order, for software engineers moving into AI: when to build an agent, how to build one, how to test it, and how the model works underneath.
  • Frontend system design — How a UI is sliced when it is a product, not a page: ownership of state, cache, routes, and what happens when the network lies.
  • TypeScript in depth — The type system as a design tool. Inference, narrowing, generics, and the errors that mean the model is wrong — not a catalog of utility types.
  • CSS in depth — See the box, then the page. Visual chapters from the box model through Flexbox surprises, Grid, selectors, and units, then backgrounds, shapes, and visual effects, each with a playground.
  • Accessibility — Foundations first (WCAG in plain words, semantic HTML, lists, alt text), then hands-on HTML labs, a full pass of WAI-ARIA 1.3, and a final fix-the-page challenge.
  • Docker — What an image is, why layers cache, and how containers find each other on a network.
  • Redis — Fifteen Redis patterns, one picture each: cache, session, lock, counter, rate limiter, queue, and when Redis is the wrong tool.
  • Kubernetes — Kubernetes from zero to operators: why it exists, Pods, Deployments and Services, then configuration, networking, storage, scheduling, scaling and security.
  • AWS — AWS networking in plain English. A VPC is a gated housing society: streets are subnets, the Internet Gateway is the main gate, and a route table is the signboard.
  • Networking: the NetRoute game — NetRoute is a packet logistics game. You wire up computers, switches, routers, firewalls and gateways, set each device, and watch glowing packets travel. If a packet gets dropped, the game shows you which header field was wrong.