# Deadlock Prevention

> What causes a database deadlock, how does the database detect it, and what do you do in practice to prevent and handle deadlocks?

Canonical: https://www.internhack.in/learn/interview/database-design/db-deadlock-prevention
Last updated: 2026-11-28

Difficulty: Intermediate

## Question

What causes a database deadlock, how does the database detect it, and what do you do in practice to prevent and handle deadlocks?

*The full answer is for InternHack members. Open the page link above to read it.*

## Concepts covered

Deadlock, Wait-for Graph, Lock Ordering, Deadlock Detection, Transaction Retry

Previous: [B-Tree vs Hash Index](https://www.internhack.in/learn/interview/database-design/db-btree-vs-hash-indexing) · Next: [Surrogate vs. Natural Keys](https://www.internhack.in/learn/interview/database-design/db-surrogate-vs-natural-key) · [All of Database Design](https://www.internhack.in/learn/interview/database-design)

## More Database Design questions

- [Columnar Storage](https://www.internhack.in/learn/interview/database-design/db-columnar-storage-olap)
- [Consistency Models](https://www.internhack.in/learn/interview/database-design/db-eventual-vs-strong-consistency)
- [ETL vs. ELT](https://www.internhack.in/learn/interview/database-design/db-etl-vs-elt)
- [Soft Delete](https://www.internhack.in/learn/interview/database-design/db-soft-delete-pattern)
- [Index Overhead](https://www.internhack.in/learn/interview/database-design/db-indexing-overhead)
- [Unique Constraints](https://www.internhack.in/learn/interview/database-design/db-unique-constraint-vs-index)

## Related

- [Learn](https://www.internhack.in/learn)
- [Interview Prep](https://www.internhack.in/learn/interview)
- [Database Design](https://www.internhack.in/learn/interview/database-design)
