System design

Stage 2 · Lesson 5 of 10

Isolation levels and concurrency anomalies

Data storage, partitioning and replication

decides what running at the same time can see of each other. Full isolation is expensive, so databases offer . Read committed, the PostgreSQL default, stops dirty reads (seeing changes that were never committed).

But a value can still change between two reads in the same transaction. Repeatable read, or , gives each transaction a frozen snapshot of the data. It still allows write skew.

For example, two doctors each check that someone else is on call, and both go off duty. Serializable behaves as if transactions ran one at a time. The cost is aborted transactions that you must retry.

Learn these anomalies by name: dirty read, , write skew. Learn the fixes too, such as SELECT ... FOR UPDATE (lock the rows you read) or an atomic UPDATE balance = balance - 10.

Common trapassuming the default level is serializable.

A question to check yourself, an AI practice session and 2 cheat sheet entries come with the full roadmap. Unlock

Resources for this stage

Start with· follow one of these

Practise

Also worth your time

Mark this stage as not done?