Make SQL transactions safe under concurrency

8 steps · about 2 h 6 min · Intermediate

  1. Frame a transaction (article, PostgreSQL documentation, 14 min)

    Start with atomic units of database work.

  2. Compare isolation levels (article, MySQL documentation, 20 min)

    Connect each isolation level to anomalies it permits or prevents.

  3. Lock rows intentionally (article, PostgreSQL documentation, 18 min)

    Use explicit locks when a read-then-write invariant needs protection.

  4. Understand MVCC snapshots (article, PostgreSQL documentation, 18 min)

    See why concurrent readers and writers can proceed together.

  5. Select rows for update (article, SQLite documentation, 15 min)

    Practice reserving work without locking an entire table.

  6. Handle serializable retries (article, PostgreSQL documentation, 16 min)

    Treat a serialization failure as a retryable outcome, not a mystery.

  7. Compare SQLite transaction modes (article, SQLite documentation, 15 min)

    See how deferred, immediate and exclusive modes differ.

  8. Set a clear transaction start (article, PostgreSQL documentation, 10 min)

    Make transaction scope visible in application code.