Interview practice question
Deadlock between app lock and database lock
Backend Engineering · Concurrency · Experienced
Your service sometimes hangs because one thread holds an in-memory lock and waits for a database row lock, while another holds the row lock and waits for the in-memory lock. How do you fix it?
What a strong answer covers
Your AI report card counts how many of these ideas you cover.
- Mixed lock types create cycles.
- Avoid holding app locks during DB calls.
- Consistent ordering across lock types.
- Timeouts on both.
- Prefer DB-only concurrency control.
Practise this topic
Start without signing up. Sign in free to get an AI report card on your answer.