Wait-for Graph
A directed graph representing which transactions wait on which resources, used to detect deadlock cycles.
Deadlock occurs when transaction A waits on a locked resource held by B, and B waits on something A holds — neither can proceed. A wait-for graph is a directed graph where nodes are transactions and an edge from A to B means "A waits on B". A cycle in the graph indicates deadlock. Detection requires the database to periodically or on each lock wait construct the graph and search for cycles — an expensive operation but necessary for correctness. Alternatives to detection include timeouts (wait at most N seconds, then abort) or prevention (order lock acquisition globally). Modern systems mix strategies: prevention for common cases, detection for edge cases.
Deadlock remains one of the least elegant aspects of concurrent systems — no clean solution, only pragmatic tradeoffs.