Concurrency Control in DBMS: Lost Updates, Locks and a Worked Schedule

See how two individually correct transactions can produce a wrong balance. Then repair the same schedule with strict two-phase locking and learn the usual exam traps.

KnowledgeGate Team

Exam prep & CS education

Updated 29 Nov 20265 min read
Concurrency Control in DBMS: Lost Updates, Locks and a Worked Schedule

Two transactions can each be correct when run alone and still leave the database wrong when their reads and writes interleave. The difficult part is seeing exactly where that error enters a schedule. An account-balance schedule exposes the lost update, and strict two-phase locking repairs the same schedule. The key skills are naming common anomalies, reading lock notation and testing a short schedule instead of memorising definitions.

Concurrency control in DBMS: what it protects

A transaction is a logical unit of database work, such as withdrawing money or recording a sale. A schedule is the order in which the read, write and commit operations of one or more transactions execute.

In a serial schedule, one transaction finishes before the next begins. In a concurrent schedule, their operations interleave. That overlap can improve resource use, so concurrency itself is not the error. The danger is an uncontrolled conflict where different transactions touch the same item and at least one writes it.

Concurrency control aims to preserve isolation and produce a result equivalent to some correct serial order while still allowing useful overlap. Transactions & Concurrency Control in DBMS introduces ACID, schedules, serializability and precedence graphs. Concurrency Control in DBMS: Anomalies, Serializability, Locking and 2PL with Worked Examples connects the full chain through precedence graphs, timestamp ordering and recoverability. Here, one lost-update schedule is run twice: first without control, then under strict 2PL, so the lock-induced wait and corrected final value can be compared operation by operation.

Concurrency anomalies: four ways interleaving fails

An anomaly is the visible symptom of an unsafe interleaving. The value traces identify the failure in each anomaly.

Anomaly

What the second transaction sees

Small value trace

Lost update

An old value, followed by its own write overwriting another update

A = 1000; T1 calculates 900; T2 calculates 1050 from the old 1000; T2 writes last

Dirty read

A value written but not committed by T1

T1 changes B: 800 -> 700; T2 reads 700; T1 aborts; valid B returns to 800

Non-repeatable read

A different committed value on its second read

T1 reads stock 25; T2 commits a sale, making it 24; T1 reads 24

Incorrect summary

A mixture of states from one transfer

Start A = 500, B = 500; a transfer debits A to 400; the summary reads 400 + 500 = 900 before B becomes 600, although the total is 1000

A dirty read depends on another transaction's uncommitted change, which may later disappear on abort. A non-repeatable read observes two different committed values. Serializability, locking, timestamp ordering and multiversion methods are control ideas used to prevent or contain such symptoms.

Lost update schedule: compute the wrong answer

Let shared item A start at 1000. T1 withdraws 100, while T2 adds 50. If both read before either writes, T1 computes 1000 - 100 = 900 locally and T2 computes 1000 + 50 = 1050 locally.

Step

T1

T2

Database A

1

r1(A) returns 1000

1000

2

r2(A) returns 1000

1000

3

Compute local 1000 - 100 = 900

1000

4

Compute local 1000 + 50 = 1050

1000

5

w1(A)

900

6

w2(A)

1050

7

Commit

Commit

1050

T2's final write replaces 900 with 1050, so T1's withdrawal is lost. Check that result against both possible serial orders:

  1. T1 then T2: (1000 - 100) + 50 = 900 + 50 = 950.

  2. T2 then T1: (1000 + 50) - 100 = 1050 - 100 = 950.

Both correct serial executions end at 950. The concurrent final value 1050 matches neither, so the schedule is not equivalent to either serial order.

Interleaved T1 and T2 schedule showing both read 1000, writes 900 and 1050, and the lost update.

Lock-based concurrency control: S, X and 2PL

A shared lock, written S(A), allows a transaction to read A. An exclusive lock, written X(A), is required to write A. Compatibility on the same data item is exact:

Lock already held

Requested S

Requested X

S

Allowed

Not allowed

X

Not allowed

Not allowed

Basic two-phase locking, or 2PL, has an expanding phase in which locks are acquired and a shrinking phase in which locks are released. After the first unlock, that transaction may not acquire a new lock. Schedules produced under 2PL are conflict serializable, but 2PL can create deadlock.

Strict 2PL adds one rule: every exclusive lock is held until commit or abort. This stops another transaction from reading an uncommitted value protected by that lock, but it still does not make deadlock impossible.

Strict 2PL repair: make T2 wait

Reuse A = 1000, T1's withdrawal of 100 and T2's addition of 50. Strict 2PL changes the sequence as follows:

  1. T1 obtains X1(A), reads 1000, computes 1000 - 100 = 900, and writes 900.

  2. T2 requests X2(A). T1 still holds the exclusive lock, so T2 must wait.

  3. T1 commits and unlocks A.

  4. T2 obtains X2(A) and now reads the committed value 900.

  5. T2 computes 900 + 50 = 950, writes 950, commits and unlocks A.

The final value is 950, exactly matching serial order T1 then T2. Waiting is deliberate coordination, not a failed transaction. If T2 gets the lock first, it writes 1000 + 50 = 1050; T1 then reads that committed value and writes 1050 - 100 = 950. The alternate safe order reaches the same final state.

Strict 2PL timeline showing T1 write 900, T2 waits for the lock, then reads 900 and writes 950.

Concurrency control exam patterns and traps

Exam questions usually compress the concept into a short schedule, a compatibility check or a protocol claim. Watch these traps:

  • Serial is not the same as serializable. A schedule may interleave operations and still be equivalent to a serial order.

  • An S lock is not enough for a write. Writing requires an X lock.

  • 2PL does not mean deadlock-free. Transactions can wait in a cycle while following 2PL.

  • Commit order does not reveal every earlier read. A transaction may already have consumed dirty data before the commits shown.

  • A correct final value is not a complete safety proof. An intermediate read may still have seen an invalid or uncommitted value.

Typical tasks are to locate the lost update in r1(A), r2(A), w1(A), w2(A); decide that S with S is compatible; flag a transaction acquiring a new lock after its first unlock as a 2PL violation; or compute 1050 for the unsafe schedule and 950 for its strict-2PL repair. Use the DBMS Transaction MCQs: 12 Solved (ACID, Locking) set to practise those decisions under time pressure.

Concurrency control short version and next step

For any schedule, ask four questions: which shared item is touched, which operations conflict, what would each serial order produce, and which protocol controls the conflict? Here, uncontrolled interleaving produced 1050; strict 2PL restored 950 by making T2 wait.

The CS Fundamentals for Exams & Placements category is the wider subject route. For a sequenced DBMS path with mixed practice, use GATE Guidance by Sanchit Sir. If you only need this concept, redraw both timelines and solve the linked transaction MCQs first.