---
title: "Need of transaction; phantom deadlock"
subject: "Distributed System"
chapter: 8
key: "semester_7/distributed_system:transaction-deadlock-phantom"
source: https://www.bctengineer.com/q/semester_7/distributed_system/transaction-deadlock-phantom
site: BCT Engineering
---

# Need of transaction; phantom deadlock

Distributed System · Chapter 8: Transaction and Concurrency Control

- Asked in: 2076 Asoj
- Video: [Part-112: Phantom Deadlock with examples - Local Wait-for Graph, Global Deadlock Detection in brief](https://www.youtube.com/watch?v=1f3IjQ-SLVY) — Knowledge Hub
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_7/distributed_system/transaction-deadlock-phantom
- Whole chapter: https://www.bctengineer.com/md/semester_7/distributed_system/chapter-8

## Question

Why is it necessary to maintain transaction? What is a deadlock and what are phantom deadlocks?

## Short answer

Transactions guarantee ACID properties, preventing lost updates and inconsistency during concurrency and crashes. Deadlock is a cyclic wait where each transaction holds a lock needed by another. A phantom deadlock is a false cycle detected from stale wait-for information across servers; a process may have already released locks, leading to an unnecessary abort.

## Answer

#### Why transactions are necessary
A **transaction** is a sequence of operations on shared data that the system treats as one indivisible unit of work: either all operations take effect or none does. It is described by the **ACID** properties:
- **Atomicity**: all or nothing.
- **Consistency**: it moves the data from one consistent state to another.
- **Isolation**: concurrent transactions do not see each other's intermediate results (appear serial).
- **Durability**: once committed, results survive crashes (stored in permanent storage).

Without transactions, concurrent access to shared data can give lost updates and inconsistent retrievals, and a crash in the middle of an operation (e.g. debit done, credit not done) leaves the data inconsistent. A transaction gives reliable, correct processing in the presence of concurrency and failures. Example: transfer of Rs 100 from account A to B must debit A and credit B together.

#### Deadlock
A **deadlock** is a state in which each transaction in a set is waiting for a lock held by another transaction in the set, so none can proceed. It is shown by a cycle in the **wait-for graph** (nodes are transactions, an edge T → U means T waits for U).

A **distributed deadlock** occurs when the wait-for cycle spans several servers. Each server sees only a part of the graph (a local wait-for graph without a local cycle), but the global graph has a cycle.

Example: T holds a lock on A at server X, and U holds a lock on B at server Y. T now requests B at Y (so T waits for U), and U requests A at X (so U waits for T).

```text
Server X: U -> T  (U waits for T on A)
Server Y: T -> U  (T waits for U on B)
Global:   T -> U -> T   (cycle = deadlock)
```

#### Phantom deadlock
A **phantom deadlock** is a deadlock that is detected but does not really exist. It arises in distributed detection because the information gathered from different servers is not from the same instant: a transaction may release its lock (and finish) after its local graph was sent but before the global graph is built. The coordinator then sees a cycle that is no longer present and may abort a transaction unnecessarily. Example: server X reports the edge T → U and server Y reports U → T. Before the coordinator builds the global graph, U is aborted (e.g. by a lock timeout) and releases its locks, so T no longer waits for U. The coordinator, working from the stale edges, still sees the cycle T → U → T and may abort T unnecessarily.

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. What problem do transactions solve when a crash occurs between debit A and credit B?
   A. They ensure all-or-nothing so data is not left inconsistent
   B. They speed up the debit
   C. They avoid locks
   D. They remove the need for logs
   Answer: A. Atomicity ensures the partial transfer is undone. (Key point: Need for transactions)

2. What does the Isolation property mean?
   A. Concurrent transactions do not see each other's intermediate results
   B. Results survive crashes
   C. All operations take effect or none
   D. Data stays on one server
   Answer: A. Transactions appear to run serially. (Key point: Isolation)

3. What is a phantom deadlock?
   A. A detected deadlock that does not really exist
   B. A deadlock with three transactions
   C. A deadlock within one server
   D. A deadlock never detected
   Answer: A. Detection finds a cycle that has already disappeared. (Key point: Phantom deadlock)

4. Why do phantom deadlocks arise in distributed detection?
   A. Local graphs are gathered at different instants, so a stale edge remains
   B. Servers use different clocks only
   C. Locks never release
   D. Wait-for graphs are never built
   Answer: A. A transaction may release its lock after its local graph was sent, leaving a stale edge and a false cycle. (Key point: Cause of phantom)

## Related in Distributed System

- [Distributed deadlock and recovery](https://www.bctengineer.com/question.md?key=semester_7%2Fdistributed_system%3Adistributed-deadlock-note) — Distributed System, chapter 8, asked 3×
- [Distributed deadlock; two-phase commit](https://www.bctengineer.com/question.md?key=semester_7%2Fdistributed_system%3Adistributed-deadlock-2pc) — Distributed System, chapter 8
- [Need of naming; Sun NFS](https://www.bctengineer.com/question.md?key=semester_7%2Fdistributed_system%3Anaming-nfs) — Distributed System, chapter 2

## Related in other subjects

- [Deadlock; necessary conditions with examples](https://www.bctengineer.com/question.md?key=semester_6%2Foperating_system%3Adeadlock-necessary-conditions-examples) — Operating System, chapter 7
- [Deadlock conditions and why all necessary](https://www.bctengineer.com/question.md?key=semester_6%2Foperating_system%3Adeadlock-conditions-why-necessary) — Operating System, chapter 7
- [Necessary conditions; deadlock prevention](https://www.bctengineer.com/question.md?key=semester_6%2Foperating_system%3Adeadlock-prevention-necessary-conditions) — Operating System, chapter 7
- [Parallelism, IPC deadlock and OS role](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3Aparallelism-deadlock-os-role) — Microprocessor, chapter 6
