# deadlocks

Published articles for deadlocks.

This is one page of public article previews, not the complete archive. Follow Next page to continue. Summaries are not the original full articles.

## Deadlocks are a lock ordering bug, and lock ordering is a design decision

DevFeed: [Deadlocks are a lock ordering bug, and lock ordering is a design decision](<https://devfeed.tech/articles/deadlocks-are-a-lock-ordering-bug-and-lock-ordering-is-a-design-decision-55691.md>)

Original publisher: [Read original article](<https://ankit-rana.com/logs/56-deadlocks-are-a-lock-ordering-bug/>)

Author: hello@ankit-rana.com

Published: 2026-09-21T00:00:00Z

Content type: article

Language: en

Sources: [Ankit Rana | Mechanical Sympathy](<https://devfeed.tech/sources/ankit-rana-mechanical-sympathy.md>)

Topics: [Deadlock](<https://devfeed.tech/topics/deadlock.md>), [ordering](<https://devfeed.tech/topics/ordering.md>), [Concurrency](<https://devfeed.tech/topics/concurrency.md>), [Database](<https://devfeed.tech/topics/database.md>), [locking](<https://devfeed.tech/topics/locking.md>), [Sorting](<https://devfeed.tech/topics/sorting.md>), [Transactions](<https://devfeed.tech/topics/transactions.md>)

Tags: [concurrency](<https://devfeed.tech/tags/concurrency.md>), [database](<https://devfeed.tech/tags/database.md>), [deadlock](<https://devfeed.tech/tags/deadlock.md>), [deadlocks](<https://devfeed.tech/tags/deadlocks.md>), [java](<https://devfeed.tech/tags/java.md>), [locking](<https://devfeed.tech/tags/locking.md>), [ordering](<https://devfeed.tech/tags/ordering.md>), [postgresql](<https://devfeed.tech/tags/postgresql.md>), [sorting](<https://devfeed.tech/tags/sorting.md>), [transactions](<https://devfeed.tech/tags/transactions.md>)

### AI overview

The article explains how database deadlocks arise when concurrent transactions acquire the same locks in opposite orders. It recommends imposing a consistent global lock order, typically by sorting identifiers, to prevent circular wait in transfers and batch operations.

### Source excerpt

A deadlock needs four conditions and the only one you control is circular wait, which is why every deadlock reduces to two transactions acquiring the same locks in opposite orders. Imposing a global order on lock acquisition, usually by sorting the identifiers before touching any row, makes the cycle impossible to form. A database deadlock is the survivable version because the engine detects it and kills a victim, and an application level deadlock across two mutexes has no detector and simply hangs.