Concurrency & Deadlocks
Software Engineer path · lesson 54 of 99Visualize Two-Phase Locking and how circular waits cause database deadlocks during concurrent transactions.
Transaction 1
Transaction 2
Growing or shrinking phase?
Sort each action into the phase of two-phase locking where it is allowed.
Tap a piece, then tap where it goes — or drag it. Tap the tray to take one back.
Growing phase
Drop items hereShrinking phase
Drop items hereTest your knowledge
If Transaction A holds a Shared Lock on Row 1, what happens if Transaction B requests an Exclusive Lock on Row 1?
The short version
Imagine two people needing a hammer and nails to work. Person A grabs the hammer. Person B grabs the nails. Person A waits for the nails, and Person B waits for the hammer. Neither can proceed. That is a deadlock.
In more depth
Concurrency Control
When multiple transactions access the same data simultaneously, databases use locks to maintain ACID properties.
Lock Types
Deadlocks
Occur when Transaction A holds Lock 1 and waits for Lock 2, while Transaction B holds Lock 2 and waits for Lock 1. The database must intervene to break the cycle by aborting one transaction.
Interview Questions
References & Further Reading
Love this visualization?
Sign up to track your progress, earn achievements, use the AI assistant, and access your personal learning dashboard.
100% free • No credit card required