Real-World Case Studies: Database Transactions and Isolation

✅ Source-checked. Each deep dive names its source, and we kept only what that source says. Found an error, or something the source doesn't support? Report it on the tracking issue.

How Google Spanner serializes transactions across the world, how PostgreSQL implements Serializable without heavy locking, and how Stripe makes retries safe with idempotency keys.


🏢 Deep Dive 1: Google Spanner, Locks Plus Clocks

Source: Spanner: Google's Globally-Distributed Database (Corbett et al., OSDI 2012). Everything in this section comes from the paper.


🐘 Deep Dive 2: PostgreSQL, Serializable Snapshot Isolation

Source: PostgreSQL documentation, Transaction Isolation. Everything in this section comes from it.


💳 Deep Dive 3: Stripe, Making Retries Safe

Source: Brandur Leach, "Designing robust and predictable APIs with idempotency" (Stripe, February 2017). Everything in this section comes from the post.

ℹ️ An earlier version of this page said Spanner uses Serializable Snapshot Isolation (its read-write transactions use two-phase locking) and described how Netflix handles billing in Aurora MySQL. We couldn't find a source we could read for the Netflix story, so we replaced it with the PostgreSQL and Stripe sections.


🎯 System Design Interview Takeaways

  1. Know the levels and their anomalies. In PostgreSQL, Repeatable Read is snapshot isolation and still allows serialization anomalies. Serializable prevents them by aborting one of the transactions.
  2. Serializable means retries. Whether it's Spanner retrying internally or PostgreSQL returning 40001, a correct design plans for transactions that must run again.
  3. Make retried requests idempotent. A client-supplied idempotency key, as Stripe uses, turns "did it happen?" into a safe retry.
  4. Keep slow network calls out of open transactions. Holding locks while waiting on a third party ties up the database. This is general practice, not a claim from the sources above.