---
title: "Short note: Flat versus nested locks"
subject: "Distributed System"
chapter: 8
key: "semester_7/distributed_system:flat-vs-nested-locks-note"
source: https://www.bctengineer.com/q/semester_7/distributed_system/flat-vs-nested-locks-note
site: BCT Engineering
---

# Short note: Flat versus nested locks

Distributed System · Chapter 8: Transaction and Concurrency Control

- Asked in: 2071 Chaitra, 3 marks
- Video: [Lecture 12: Distributed Systems: Concurrency control in distributed transactions](https://www.youtube.com/watch?v=kTCtHRxJMr4) — kaushal bhardwaj
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_7/distributed_system/flat-vs-nested-locks-note
- Whole chapter: https://www.bctengineer.com/md/semester_7/distributed_system/chapter-8

## Question

Write a short note on flat versus nested locks.

## Short answer

Flat locks are held by a single transaction and released at commit/abort, conflicting with any other transaction. Nested locks allow sub-transactions to acquire locks; a child can lock if conflicting holders are ancestors, and upon commit locks are inherited by the parent, increasing intra-transaction concurrency while maintaining serial equivalence.

## Answer

In a **flat transaction** locks are held by one transaction, and the usual rules apply: locks are acquired as objects are accessed (growing phase), and under strict 2PL all are released together at commit or abort. Two locks conflict if they are from different transactions and at least one is a write.

In **nested transactions**, locks belong to sub-transactions, and the following rules are used (Moss):
- A sub-transaction can acquire a read lock if every other holder of a write lock on the object is an **ancestor**.
- It can acquire a write lock if every other holder of a read or write lock is an ancestor.
- When a sub-transaction **commits**, its locks are **inherited** by its parent (the parent now holds them).
- When a sub-transaction **aborts**, its locks are discarded; if the parent held the lock earlier, it still holds it.

| Point | Flat locks | Nested locks |
|---|---|---|
| Holder | One transaction | Sub-transaction (and parent by inheritance) |
| Release | At commit/abort | Passed to parent at child commit; final release at top level |
| Concurrency | Between top-level transactions | Also between siblings, within a transaction |
| Conflict rule | Any other transaction | Non-ancestors only |

Nested locking increases concurrency inside a transaction while keeping serial equivalence among siblings.

## Check yourself

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

1. In nested transactions, a sub-transaction can acquire a write lock if:
   A. No lock at all is held
   B. Every other holder of a read or write lock is an ancestor
   C. Its parent has already committed
   D. It is the oldest sibling
   Answer: B. Only ancestors holding locks do not conflict with the sub-transaction. (Key point: Nested write lock rule)

2. When a sub-transaction aborts, what happens to its locks?
   A. The parent inherits them
   B. They are discarded; the parent keeps any lock it held earlier
   C. All locks of the parent are released
   D. They pass to siblings
   Answer: B. Abort discards the child's locks, while earlier parent locks remain. (Key point: Lock on child commit/abort)

3. What extra concurrency do nested locks provide compared with flat locks?
   A. Concurrency among top-level transactions only
   B. Concurrency between sibling sub-transactions within one transaction
   C. No locks needed
   D. Transactions never conflict
   Answer: B. Siblings can run concurrently while serial equivalence is maintained among them. (Key point: Concurrency benefit)

## Related in Distributed System

- [Flat/nested transactions; concurrency control](https://www.bctengineer.com/question.md?key=semester_7%2Fdistributed_system%3Aflat-nested-cc-methods) — 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

## Related in other subjects

- [Flat roof versus pitched roof](https://www.bctengineer.com/question.md?key=semester_6%2Fbuilding_technology%3Aflat-vs-pitched) — Building Technology, chapter 4, asked 2×
