DeadlockError: Two or more threads/processes are each waiting for a resource the other holds — none of them can ever proceed. A deadlock error tells you the system detected a deadlock and stopped one of the parties. In MySQL it reads Deadlock found when trying to get lock; try restarting transaction. PostgreSQL reports deadlock detected.
The database chooses a victim transaction, rolls it back and lets the others continue. Your code receives the error and the work in that transaction is undone.
What should you keep in mind with DeadlockError?
Occasional deadlocks under heavy load are normal, and the right response is to retry the transaction. Laravel's DB::transaction() accepts a number of attempts for exactly this reason. Frequent deadlocks point to a design problem: transactions that run too long, rows updated in different orders by different code paths, or missing indexes that make the database lock more rows than needed. The database's deadlock log shows which queries collided.
Use when code runs things at the same time - threads, async/await, queues and workers, parallel requests, cron jobs, webhooks that retry - or when a bug only happens "sometimes" or under load. Covers race conditions, deadlocks, mutexes/locks, atomic operations, idempotency, message queues and backpressure, with Laravel and database examples.