DATABASE
    advanced

    Concurrency & Deadlocks

    Software Engineer path · lesson 54 of 99
    Waiting to start...
    Step 0 / 7

    Transaction 1

    Row A
    Row B
    Row A
    Row B

    Transaction 2

    Row B
    Row A

    Growing or shrinking phase?

    Sort

    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 here

    Shrinking phase

    Drop items here
    6 pieces left to place

    Test your knowledge

    20 questions
    Question 1 of 20
    Score: 0

    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

    Shared (S): Allows reading. Multiple transactions can hold an S lock on the same row.
    Exclusive (X): Required for writing. Only one transaction can hold an X lock.

    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

    Google
    Stripe
    Amazon

    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