SpinTheMic
Pro

Interview practice question

Transfer method deadlocks

Backend Engineering · Concurrency · Intermediate

A transfer method locks the "from" account then the "to" account. Two transfers in opposite directions deadlock. How do you fix it?

What a strong answer covers

Your AI report card counts how many of these ideas you cover.

  • Opposite lock order causes circular wait.
  • Always lock in consistent order (by ID).
  • tryLock with timeout as backup.
  • Or single lock/serial per account.
  • Or use DB transactions.
Practise this topic

Start without signing up. Sign in free to get an AI report card on your answer.

See all topics