- Asked 2/15
- 2075 Chaitra · 2+6 marks
- 2070 Chaitra · 2+6 marks
Nested vs distributed transaction; 2PC
Short answer
Nested transactions have a tree of sub-transactions that can run concurrently, where a child abort does not abort the parent. Distributed transactions involve multiple servers and use two-phase commit (2PC) for atomicity. 2PC: coordinator asks canCommit?, if all vote Yes it sends doCommit, else doAbort; participants then commit or abort accordingly.
Compare nested transactions and distributed transactions with examples. Explain the two-phase commit protocol / how commitment is ensured in handling distributed transactions.
Nested transactions versus distributed transactions
-
Nested transaction: a transaction made of sub-transactions in a tree. The top-level transaction contains child transactions, which may contain their own children. Sub-transactions at the same level can run concurrently, and a sub-transaction can abort without aborting its parent; the parent may retry or choose another action. Example: a book trip transaction with sub-transactions book flight, book hotel, book taxi. If the taxi booking fails, the parent can try another company.
-
Distributed transaction: a (flat or nested) transaction whose operations access objects on several servers. What matters is not the structure of the transaction but that its data are distributed. It needs a coordinator to commit or abort it at all servers. Example: transferring money from an account at bank server X to an account at server Y.
| Point | Nested transaction | Distributed transaction |
|---|---|---|
| Basis | Structure of the transaction (tree of sub-transactions) | Location of the objects (many servers) |
| Parts | Sub-transactions | Operations at different servers |
| Concurrency | Sub-transactions run in parallel | Servers run parts concurrently |
| Partial failure | A child can abort without the parent aborting | Whole transaction aborts if one server aborts |
| Commit | Provisional commit of children, final at top | Atomic commit protocol (2PC) |
| Can be single server? | Yes | No |
A transaction can be both (a nested distributed transaction, e.g. a book trip that has sub-transactions at airline, hotel and taxi servers).
Commitment: two-phase commit
The two-phase commit protocol (2PC) makes sure that all servers (participants) of a distributed transaction either all commit or all abort. One server acts as the coordinator (usually the one that the client contacted); others are participants.
Phase 1: voting
- The coordinator sends canCommit? to every participant.
- Each participant replies Yes (it has saved the transaction's changes to permanent storage and is prepared; it can no longer unilaterally abort) or No (it aborts at once).
Phase 2: completion 3. If all votes (including the coordinator's own) are Yes, the coordinator records the decision and sends doCommit; if any vote is No or a timeout occurs, it sends doAbort. 4. Participants carry out the decision and send haveCommitted to the coordinator.
Coordinator Participants
|--- canCommit? ------->|
|<------ Yes / No ------|
| (decide, log) |
|--- doCommit/doAbort ->|
|<---- haveCommitted ---|
Failures
- If a participant crashes before voting, the coordinator times out and aborts.
- A participant that has voted Yes is in the uncertain state; if the coordinator fails it must wait (it blocks) or ask other participants for the decision.
- On recovery, servers use their logs to complete the protocol.
Drawbacks: blocking if the coordinator fails, and extra messages and delays (about 3N messages for N participants).
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- Distributed deadlock; two-phase commit · Distributed System, chapter 8
- Atomic commitment protocols (2PC, 3PC) · Distributed System, chapter 8
- Distributed and nested distributed transactions · Distributed System, chapter 8
- Short note: Two-phase commit · Distributed System, chapter 8 · asked 2×
- Transaction, nested transaction, atomicity · Distributed System, chapter 8
- Flat/nested transactions; optimistic CC · Distributed System, chapter 8