---
title: "Locks in transactions; lost update"
subject: "Distributed System"
chapter: 8
key: "semester_7/distributed_system:lock-benefits-lost-update"
source: https://www.bctengineer.com/q/semester_7/distributed_system/lock-benefits-lost-update
site: BCT Engineering
---

# Locks in transactions; lost update

Distributed System · Chapter 8: Transaction and Concurrency Control

- Asked in: 2074 Chaitra, 4+4 marks
- Video: [Lec-91: All Concurrency Problems | Dirty Read | Incorrect Summary | Lost Update | Phantom Read](https://www.youtube.com/watch?v=oP8yLMjmszE) — Gate Smashers
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_7/distributed_system/lock-benefits-lost-update
- Whole chapter: https://www.bctengineer.com/md/semester_7/distributed_system/chapter-8

## Question

What are the benefits and drawbacks of using lock in Transaction Processing? Explain the lost-update problems with suitable example.

## Short answer

Locks guarantee serial equivalence with 2PL, prevent dirty reads and cascading aborts with strict locking. Drawbacks are deadlock, overhead, and reduced concurrency. Lost update occurs when two transactions read the same value and both write, overwriting each other; for example, account 100, T adds 10, U adds 20, final 120 not 130. Exclusive lock prevents it.

## Answer

#### Locks in transaction processing
A **lock** is a variable associated with a data item that controls concurrent access. A transaction must obtain the lock before it reads or writes the item, and releases it when finished. Common modes are **read (shared) lock** and **write (exclusive) lock**; several transactions can hold read locks together, but a write lock excludes all others. In **two-phase locking (2PL)** a transaction has a growing phase (acquires locks) followed by a shrinking phase (releases locks, never acquires again). **Strict 2PL** holds all locks until commit or abort, which prevents dirty reads and cascading aborts.

**Benefits**
- They guarantee serial equivalence (isolation) when 2PL is used.
- Simple, well-understood and widely implemented.
- Strict locking prevents dirty reads and cascading aborts.

**Drawbacks**
- **Deadlock** can occur when transactions wait for each other in a cycle.
- Lock management has overhead (lock table, acquiring and releasing).
- Locks reduce concurrency; short transactions wait for long ones.
- Locks may be held across a network in distributed systems, and a crashed holder blocks others until timeout.
- Early release (non-strict) can cause cascading aborts.

#### Lost update problem
The **lost update problem** occurs when two transactions read the same value and both write back results based on it, so one update overwrites the other.

Example: account A has Rs 100. T reads A (100) and adds Rs 10; U reads A (100) and adds Rs 20.

```text
T: bal = A.get()      -> 100
U: bal = A.get()      -> 100
T: A.set(bal + 10)    -> 110
U: A.set(bal + 20)    -> 120   (T's update is lost)
```

The correct final value is 130 in any serial order. Locking prevents this: with an exclusive lock on A, U cannot read A until T commits and releases the lock, so U sees 110 and writes 130.

## Check yourself

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

1. What main guarantee do locks with two-phase locking provide?
   A. Freedom from deadlock
   B. Serial equivalence (isolation)
   C. No lock overhead
   D. Higher concurrency than any other method
   Answer: B. 2PL ensures that concurrent transactions are equivalent to some serial order, giving isolation. (Key point: Benefit of 2PL)

2. Which is a drawback of using locks?
   A. Deadlock can occur when transactions wait in a cycle
   B. Dirty reads are always allowed
   C. Lost updates become possible
   D. Transactions cannot be aborted
   Answer: A. Transactions waiting for each other's locks in a cycle cause deadlock; locks also add overhead and reduce concurrency. (Key point: Drawback of locking)

3. Account A has Rs 100. T reads 100 and adds 10, U reads 100 and adds 20, then both write. With no locking, what is the final balance and why?
   A. 130, since both additions apply
   B. 110, because U's write is lost
   C. 120, because T's update is overwritten
   D. 100, because both writes are undone
   Answer: C. Both read 100; T writes 110, then U writes 120, overwriting T's update. (Key point: Lost update example)

4. How does locking prevent the lost update in this example?
   A. U is blocked from reading A until T commits, so U sees 110 and writes 130
   B. T is aborted so U can proceed
   C. U writes first, then T overwrites
   D. Both are given the same timestamp
   Answer: A. Once T holds the lock, U must wait and then reads the updated value 110, giving the correct 130. (Key point: How locks prevent lost update)

## Related in Distributed System

- [Parent-child transactions; locking problems](https://www.bctengineer.com/question.md?key=semester_7%2Fdistributed_system%3Aparent-child-locking) — Distributed System, chapter 8
- [Lock; distributed CC; deadlock situation](https://www.bctengineer.com/question.md?key=semester_7%2Fdistributed_system%3Alock-cc-deadlock-situation) — Distributed System, chapter 8
- [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
- [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×
- [Distributed and nested distributed transactions](https://www.bctengineer.com/question.md?key=semester_7%2Fdistributed_system%3Adistributed-transaction-nested) — Distributed System, chapter 8

## Related in other subjects

- [Random access file transaction processing](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Arandom-access-transaction) — Object Oriented Programming, chapter 8
- [Benefits and problems of reuse; reuse planning](https://www.bctengineer.com/question.md?key=semester_5%2Fsoftware_engineering%3Areuse-benefits-problems) — Software Engineering, chapter 5
- [Interpret: computers and word processing](https://www.bctengineer.com/question.md?key=semester_5%2Fcommunication_english%3Ainterpret-computers-solved-problems) — Communication English, chapter 1
- [Apriori on 8 transactions, 25% support](https://www.bctengineer.com/question.md?key=semester_7%2Fdata_mining%3Aapriori-b65-transactions) — Data Mining, chapter 4
