SQL & PostgreSQLInterview preparation
Advanced·Concept·2 min read

What are isolation levels and read anomalies?

Practice this question

Definition:

Isolation defines how one transaction can observe and interfere with concurrent transactions. Different levels allow different anomalies to balance correctness, concurrency and retry cost. PostgreSQL uses snapshots under MVCC, but even a stable snapshot does not automatically make every business decision safe against concurrent writes.

Key points:

  • Dirty read: uncommitted data; non-repeatable read: a row changes; phantom: matching rows change.
  • PostgreSQL Read Committed uses a new snapshot per statement; Repeatable Read uses a stable transaction snapshot.
  • Serializable prevents serialization anomalies, but applications must retry failed transactions; PostgreSQL treats Read Uncommitted as Read Committed.

Reference: PostgreSQL isolation.

  • Repeatable Read can still allow write-skew anomalies; Serializable detects incompatible concurrent histories and may abort a transaction.

Comparison — PostgreSQL:

LevelTypical read viewImportant limitation
Read CommittedNew snapshot per statementA later read may see a changed result
Repeatable ReadStable transaction snapshot, plus own writesSome cross-row business anomalies remain
SerializableSuccessful transactions fit a serial orderConflicting work may need a full retry

Interview point:

  • Explain a real anomaly and the chosen protection, then mention whole-transaction retries where the database can reject conflicting work.
Adapted from 05_SQL_POSTGRESQL.md · “What are isolation levels and read anomalies?”. Code examples are study fragments. Difficulty and core labels are editorial estimates; version-specific behavior should be checked against your project.