Graph
Deadlock

⛔Deadlock

NEW

A concurrency failure where transactions or processes wait indefinitely on each other’s locks, preventing progress.

DESCRIPTION

Deadlock occurs when two or more transactions hold locks that the others need, causing circular waiting. Databases detect deadlocks via wait-for graphs or timeouts and abort one transaction to break the cycle. Common causes include inconsistent lock ordering, large transaction scopes, and exclusive locks on contended resources. Prevention strategies include consistent lock ordering, shorter transactions, appropriate isolation levels, and careful indexing. Monitoring and logging deadlock events are essential to diagnose and remediate issues.

ALTERNATIVE DEFINITIONS

Wikipedia

In concurrent computing, a deadlock is a situation in which two or more competing actions are waiting for the other to finish, and thus neither ever does.

General computing framing beyond databases.

Source

Microsoft Learn

A deadlock occurs when two or more sessions block each other because each session holds a lock on a resource that the other sessions are trying to lock.

Database-specific description with sessions and resources.

Source

PostgreSQL Documentation

A deadlock is a situation where two or more transactions wait for each other, preventing any of them from proceeding.

Focuses on transactional waiting and resolution.

Source

Locking Two-Phase Locking Wait-For Graph Starvation Timeout Isolation Levels Transaction Isolation (ACID) Deadlock Detection

COMPETING TERMS

Livelock

KNOWLEDGE AREAS

Data Storage & Operations Data Engineering Software Engineering Infrastructure

TARGET AUDIENCE

Software Developer Data Engineer DevOps Engineer IT Manager Cloud Architect

EXTERNAL SOURCES

TOP QUESTIONS

What is a Deadlock in databases?

It’s a circular wait where transactions lock resources needed by each other, preventing progress. Databases detect and resolve by aborting one transaction.

Category: Overview

What causes Deadlocks most often?

Inconsistent lock ordering, long transactions, and high contention on exclusive locks. Poor indexing can exacerbate locking conflicts.

Category: Mistakes

How can Deadlocks be prevented?

Use consistent lock ordering, keep transactions short, choose appropriate isolation levels, and reduce contention with indexing and batching.

Category: HowTo

What is the risk of Deadlocks in production?

They cause aborted transactions, user-facing errors, and performance degradation. Frequent deadlocks indicate design or operational issues.

Category: Risk

How are Deadlocks detected?

Wait-for graphs and periodic checks identify cycles. Timeouts provide a fallback. Logs help pinpoint offending statements.

Category: Management

What is the difference between Deadlock and Livelock?

In a livelock, processes change states without progress; in a deadlock, they remain blocked waiting for each other.

Category: Misunderstanding

What hot topics exist around Deadlocks?

Optimistic concurrency and lock-free structures reduce deadlock frequency, while MVCC improves read-write concurrency.

Category: Topic

How should applications handle Deadlocks?

Catch exceptions, implement retries with backoff, and instrument telemetry to analyze lock contention patterns.

Category: Requirements

Do higher isolation levels affect Deadlocks?

Yes, strict levels can increase contention and deadlock likelihood. Balance isolation with performance needs.

Category: Opinion