</> MAANG.io
system design · 201

Intermediate

Master system design interviews with scalable architecture patterns, distributed systems, and real-world design challenges.

0/124 solved 0% complete

Two-Phase Locking (2PL)

maang.io System Design Series


Two-phase locking is the textbook mechanism for serializable transactions: a transaction first only acquires locks (the growing phase), then only releases them (the shrinking phase) — never acquiring after releasing. That discipline guarantees a serializable schedule, at the cost of deadlocks, which the database detects and breaks. It's the counterpoint to MVCC and a pillar of the ACID story.

This deep dive comes in three parts:

  • Foundations & Core Concepts — shared/exclusive locks, the two phases, and strict 2PL.
  • Internals — deadlock detection, predicate locks for phantoms, and the MVCC contrast, with worked numbers.
  • Interview — Staff/Principal Q&A: isolation levels, deadlock handling, and locking vs MVCC.

Sign in to MAANG.io

Use your Google or Microsoft account — no password to remember.

Continue with Google Continue with Microsoft

Please accept the terms above to continue.