Backend development

Stage 2 · Lesson 8 of 11

Isolation levels and locking

Relational databases and SQL

decide what transactions running at the same time can see of each other. 's default is Read Committed. Each statement sees data committed before it started, so two reads in one transaction can return different values.

Repeatable Read gives the whole transaction one fixed snapshot of the data. Serializable makes transactions behave as if they ran one at a time, but some will fail and must be retried. For "check, then update" logic you have two .

You can lock the row with SELECT ... FOR UPDATE. Or you can use optimistic locking: a version column that the UPDATE checks has not changed. Without either, you risk a lost update, where one write silently overwrites another.

Common trapchoosing Serializable everywhere without retry code; failures are expected under it, and the application must run the transaction again.

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

Resources for this stage

Start with· follow one of these

Practise

Keep handy

  • Query macros, pools, transactions, migrations and offline mode, with PostgreSQL examples

Also worth your time

Mark this stage as not done?