Lesson 14 of 19
17. Transactions and Locking

Memory card and where the analogy breaks

3 min read+10 XP

The memory card (tear this page out)

#QuestionMemory code
17.1Transaction?Seat and payment, together or not at all
17.2ACID in depth?Whole, legal, private, permanent
17.3Lost update?Don't read, think and write back; let the database subtract
17.4Read anomalies?Unfinished, changed, or newly appeared: three ways to read a lie
17.5Isolation levels?The stronger the isolation, the more it's like one clerk at a time, and the more you wait or retry
17.6Pessimistic locking?Hand on the seat before you sit
17.7Optimistic locking?Check it's still free as you sit
17.8Deadlocks?Grab seats in the same order and nobody waits in a circle
17.9Distributed locks?A lock that can expire can be held twice, so number every holder
17.102PC?Everyone says "ready", then everyone says "done"; one "no" cancels all
17.11Sagas?Do it step by step, and keep an undo for every step
17.12Seat holds?Hold it, pay for it, or lose it

The whole chapter in one line: All or nothing inside one database, a hand or a last-moment check on every contested seat, and step-by-step with undo across services.

Where the analogy breaks

  • Two passengers arguing is visible. Two transactions overwriting each other is silent: a lost update leaves no error, just wrong numbers.
  • A clerk can't be in two places. A transaction can be retried, aborted or replayed, so every step must be safe to run more than once.
  • A refund feels like an undo. Some actions can't be undone at all (a sent email, a shipped parcel), which is why sagas put them last.

Quick check

Five questions on this chapter. Pick an answer, then check it.

quiz