Transactions and Isolation Levels
Reproduce the classic concurrency bugs — dirty reads, non-repeatable reads, write skew — with two live psql sessions, then fix them by choosing the right isolation level and understanding what each one actually costs you.
Prerequisites: PostgreSQL Fundamentals; Indexing and Query Optimization.
Isolation is the part of ACID that governs what one transaction is allowed to see of another transaction's in-progress, not-yet-committed work. Without any isolation at all, you'd be exposed to a menu of well-defined concurrency bugs: a dirty read (seeing another transaction's uncommitted changes, which might get rolled back), a non-repeatable read (re-reading the same row twice in one transaction and getting different values because someone else committed a change in between), and a phantom read (re-running the same range query twice and getting a different set of rows). Postgres's MVCC (multi-version concurrency control) design makes dirty reads impossible at any isolation level — every transaction sees a consistent snapshot, never raw uncommitted state — but the other two phenomena are very much possible depending on which isolation level you choose, and this project exists to make that concrete rather than theoretical.
Read Committed: the default, and its non-repeatable read
Repeatable Read and its write skew hole
Serializable: closing the write skew hole with SSI
Explicit locking as an alternative to raising isolation
Secret Mission: build a retry-safe Serializable transaction wrapper
Before You Go
Test what you just learned
Self-testing is one of the best ways to retain new skills. Unlock project quizzes to check your understanding.
Log in to unlock0 / 7 complete
