Every database faces the same puzzle: thousands of users read and write simultaneously, yet each one expects to see a consistent view of the data. If you transfer money between two accounts, the amount cannot disappear between the debit and the credit, no matter what anyone else is doing at that instant.
The solution almost every relational database relies on is Two-Phase Locking (2PL), invented by Eswaran, Gray, Lorie, and Traiger at IBM in 1976. The idea is disarmingly simple: a transaction may acquire as many locks as it needs, but the moment it releases one lock, it may never acquire another. This creates two clean phases — a growing phase (lock accumulation) and a shrinking phase (lock release). You collect your tools, do your work, then put them all away.
That single rule is provably sufficient for serializability — the strongest correctness guarantee in databases, meaning the outcome of any concurrent execution is identical to some serial order. But the rule carries a price: two transactions can each hold a lock the other needs, and both will wait forever. Deadlock is not a bug in 2PL; it is a structural consequence of the guarantee it provides.
Related: if you want to understand why serializability matters at all, start with P vs NP — the deeper question of whether efficient algorithms exist for hard verification problems.
Comments
Loading comments...