Distributed

Lesson 02.7

Deadlocks & retries

A deadlock forms when transactions each hold a lock the other needs, so the database must abort one and the application must retry it.

Two kids, two toys

Ava and Ben each want to play with both the 🚗 car and the 🧸 teddy. You can only play once you're holding both.

Ava likes to grab the 🚗 first. Ben likes to grab the 🧸 first. What could go wrong?

In this lesson you'll

  1. 1Explain why two workers waiting on each other get stuck, and how a fixed order avoids it
  2. 2Watch a normal playtime.
  3. 3Guess what happens when they grab at the same time.
  4. 4Find a rule so they never get stuck.