---
title: "Distributed and nested distributed transactions"
subject: "Distributed System"
chapter: 8
key: "semester_7/distributed_system:distributed-transaction-nested"
source: https://www.bctengineer.com/q/semester_7/distributed_system/distributed-transaction-nested
site: BCT Engineering
---

# Distributed and nested distributed transactions

Distributed System · Chapter 8: Transaction and Concurrency Control

- Asked in: Model question
- Video: [DS37:Distributed Transactions: Flat and nested distributed transactions  in distributed sustem](https://www.youtube.com/watch?v=ChjUflFtS6s) — University Academy
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_7/distributed_system/distributed-transaction-nested
- Whole chapter: https://www.bctengineer.com/md/semester_7/distributed_system/chapter-8

## Question

Define distributed transaction and nested distributed transaction with examples.

## Short answer

A distributed transaction spans multiple servers, requiring atomic commit to ensure all-or-nothing semantics, e.g., inter-bank transfer. A nested distributed transaction decomposes into sub-transactions at different servers that run concurrently and provisionally commit; only the top-level commit makes them permanent, allowing independent aborts, e.g., trip booking with flight and hotel.

## Answer

#### Distributed transaction
A **distributed transaction** is a transaction whose operations access objects managed by **several servers**. It can be flat (the client makes requests one after another to different servers) or nested. It must still satisfy ACID, so all servers must commit or all abort, which needs a **coordinator** and an atomic commit protocol (two-phase commit).

Example: a funds transfer where account A is at Bank server X and account B is at server Y.

```text
Client --begin--> Coordinator (X)
   T: X.withdraw(A,100)
   T: Y.deposit(B,100)
Client --commit--> 2PC between X and Y
```
When server Y is first used, it joins the transaction by informing the coordinator, which keeps a list of participants.

#### Nested distributed transaction
A **nested distributed transaction** is a transaction with a tree of sub-transactions in which the sub-transactions run on different servers. Each sub-transaction can run in parallel at its server, can abort independently, and commits provisionally; the real commit happens only when the top-level transaction commits (using a nested two-phase commit that involves all servers).

Example: a *book trip* transaction T starts sub-transactions T1 (flight at server F), T2 (hotel at server H), T3 (taxi at server C). T2 may abort if no room, and T can then try another hotel.

```text
            T (client)
        /     |      \
 T1 (F)   T2 (H)    T3 (C)
```
Each server records the sub-transactions it holds; the coordinator of the top level finds out which participants did work (and which provisionally committed or aborted) before running the commit protocol. Rules: if the parent aborts, all children abort; a child's locks pass to the parent when it commits.

## Check yourself

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

1. What makes a transaction a distributed transaction?
   A. It has more than one client
   B. Its operations access objects managed by several servers
   C. It uses nested sub-transactions
   D. It runs in parallel threads
   Answer: B. A distributed transaction spans objects at multiple servers, and must still be atomic across them. (Key point: Distributed transaction)

2. How do the servers of a distributed transaction reach a common commit or abort outcome?
   A. Each server decides independently
   B. The coordinator runs an atomic commit protocol such as two-phase commit
   C. The client commits at each server in turn
   D. The oldest server decides alone
   Answer: B. A coordinator and 2PC ensure that all servers commit or all abort. (Key point: Atomic commit)

3. In a nested distributed transaction, when does a sub-transaction's commit become permanent?
   A. Immediately when the sub-transaction finishes
   B. Only when the top-level transaction commits
   C. When the child's server restarts
   D. When the parent starts
   Answer: B. Sub-transactions commit provisionally; the real commit happens at the top level. (Key point: Nested sub-transactions)

4. In the book-trip example, what can happen if the hotel sub-transaction T2 aborts?
   A. T and all other sub-transactions must abort
   B. T can try another hotel and continue
   C. The flight booking is automatically permanent
   D. The coordinator ends the system
   Answer: B. Sub-transactions can abort independently, letting the parent choose an alternative. (Key point: Independent abort)

## Related in Distributed System

- [Nested vs distributed transaction; 2PC](https://www.bctengineer.com/question.md?key=semester_7%2Fdistributed_system%3Anested-vs-distributed-2pc) — Distributed System, chapter 8, asked 2×
- [Transaction, nested transaction, atomicity](https://www.bctengineer.com/question.md?key=semester_7%2Fdistributed_system%3Atransaction-nested-atomicity) — Distributed System, chapter 8
- [Flat/nested transactions; optimistic CC](https://www.bctengineer.com/question.md?key=semester_7%2Fdistributed_system%3Aflat-nested-optimistic) — Distributed System, chapter 8
- [Flat/nested transactions; concurrency control](https://www.bctengineer.com/question.md?key=semester_7%2Fdistributed_system%3Aflat-nested-cc-methods) — Distributed System, chapter 8
- [Nested transactions; optimistic CC advantages](https://www.bctengineer.com/question.md?key=semester_7%2Fdistributed_system%3Anested-optimistic-advantages) — Distributed System, chapter 8
- [Need of transaction; phantom deadlock](https://www.bctengineer.com/question.md?key=semester_7%2Fdistributed_system%3Atransaction-deadlock-phantom) — Distributed System, chapter 8
