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

# Transaction, nested transaction, atomicity

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/transaction-nested-atomicity
- Whole chapter: https://www.bctengineer.com/md/semester_7/distributed_system/chapter-8

## Question

Define transaction and nested transaction with examples. Explain how an atomicity is gained in transactions.

## Short answer

A transaction is an indivisible unit of operations with ACID properties, e.g., a bank transfer. Nested transactions are trees of sub-transactions that commit provisionally; a parent can retry if a child aborts. Atomicity is enforced by tentative updates, write-ahead logs for undo/redo, and strict two-phase locking with atomic commit.

## Answer

#### Transaction
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).

Example: a bank transfer *debit A; credit B* in one transaction.

#### Nested transaction
- **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.

Rules of nested transactions:
- A sub-transaction commits only provisionally; its result becomes permanent only when all its ancestors commit up to the top level.
- If a parent aborts, all its sub-transactions abort, even those that provisionally committed.
- A child sees the parent's changes, but the parent does not see the child's until the child commits.

#### How atomicity is gained
Atomicity means that after a failure or abort no partial effect remains. It is achieved by:
1. **Private workspace / tentative versions**: updates are made on tentative copies, and they become permanent only at commit.
2. **Write-ahead log**: before any change, the old and new values are written to a log on stable storage. On abort or crash, uncommitted changes are **undone**, and committed ones **redone** from the log.
3. **Shadow paging**: the database is switched to the new page table atomically at commit.
4. **Atomic commit (two-phase commit)** for distributed transactions, so all servers commit or all abort.
5. **Concurrency control** (strict 2PL), which stops other transactions from seeing uncommitted data and so avoids cascading aborts.

## Check yourself

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

1. In a nested transaction, what happens when a child sub-transaction aborts?
   A. The parent aborts automatically
   B. The parent can retry or choose another action
   C. All siblings commit
   D. The top level commits
   Answer: B. A child can abort without aborting the parent, e.g. trying another taxi company. (Key point: Nested transaction abort)

2. Which statement about visibility is correct?
   A. A child sees the parent's changes, but the parent does not see the child's until the child commits
   B. The parent always sees the child's changes
   C. A child cannot see the parent's changes
   D. Siblings share all changes
   Answer: A. Visibility is one-way until the child commits. (Key point: Child visibility)

3. What is the role of the write-ahead log in atomicity?
   A. Old and new values are logged first so uncommitted changes can be undone and committed ones redone
   B. It speeds up reads
   C. It replaces locks
   D. It orders timestamps
   Answer: A. The log on stable storage allows recovery after abort or crash. (Key point: Write-ahead log)

4. How do tentative versions help atomicity?
   A. Updates become permanent only at commit, so an abort leaves no effect
   B. They avoid commits
   C. They allow dirty reads
   D. They bypass logging
   Answer: A. Changes are made on tentative copies and discarded on abort. (Key point: Private workspace)

## Related in Distributed System

- [Flat/nested transactions; optimistic CC](https://www.bctengineer.com/question.md?key=semester_7%2Fdistributed_system%3Aflat-nested-optimistic) — Distributed System, chapter 8
- [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×
- [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
- [Distributed and nested distributed transactions](https://www.bctengineer.com/question.md?key=semester_7%2Fdistributed_system%3Adistributed-transaction-nested) — Distributed System, chapter 8
- [Locks in transactions; lost update](https://www.bctengineer.com/question.md?key=semester_7%2Fdistributed_system%3Alock-benefits-lost-update) — Distributed System, chapter 8

## Related in other subjects

- [Apriori on 8 transactions, 25% support](https://www.bctengineer.com/question.md?key=semester_7%2Fdata_mining%3Aapriori-b65-transactions) — Data Mining, chapter 4
- [Apriori on four transactions, support 2](https://www.bctengineer.com/question.md?key=semester_7%2Fdata_mining%3Aapriori-y63-min-support-2) — Data Mining, chapter 4
