DBMS slides 📂 Transactions and Concurrency · 1 of 5 34 min read

Transactions & Concurrency: Transaction States and ACID Properties

A transaction bundles many operations into one all-or-nothing unit. This tutorial covers the transaction lifecycle — Active, Partially Committed, Committed, Failed, Aborted — the four ACID properties (Atomicity, Consistency, Isolation, Durability) with the classic bank-transfer example, and the concurrency anomalies like lost update that isolation exists to prevent. Includes animated diagrams and worked schedules.

Transactions & ACID Properties

How a database treats many operations as one indivisible unit — the transaction lifecycle, the four ACID guarantees, and the concurrency anomalies isolation exists to stop.
All-or-Nothing Transaction States A·C·I·D Concurrency

Press Next → or use ← → arrow keys

Section 01

The Story — The ATM That Lost ₹5,000

Two steps that must happen together
You transfer ₹5,000 from your savings to a friend's account. The bank must (1) debit your account and (2) credit theirs. If the power fails between the two steps, the money leaves your account but never arrives — it simply vanishes. Neither balance is correct.
💡
Why Transactions Exist

A database must treat those two steps as one indivisible unit — it either completes entirely or has no effect at all. That unit is a transaction.

Section 02

A Transaction & Its Four Operations

📦
Definition

A transaction is a sequence of one or more operations treated as a single, indivisible unit. It either commits (all changes permanent) or rolls back (no effect). There is no half-done state.

📖
Read(X)
Load item X into a local buffer. No database change yet.
✍️
Write(X)
Write the modified value back. May stay buffered for now.
✅
Commit
Success — all changes become permanent and visible.
↺
Rollback
Failure — undo everything, restore the prior state.
🎯
Every Transaction Ends One of Two Ways

Committed or Aborted — there is no third outcome.

Section 02 · Example

The Classic Fund Transfer

BEGIN TRANSACTION;
UPDATE accounts
  SET balance = balance - 5000
  WHERE acc_id = 'A';
UPDATE accounts
  SET balance = balance + 5000
  WHERE acc_id = 'B';
COMMIT;
Account A10000 → 5000 Account B2000 → 7000 ₹5000 debit A, then credit B — as one unit
⚠️
The Danger Zone

Abstract steps: Read(A) · A := A−5000 · Write(A) · Read(B) · B := B+5000 · Write(B) · Commit. If a crash strikes after Write(A) but before Write(B), ₹5,000 is deducted but never credited — the database is inconsistent. Atomicity is what prevents this.

Section 03

The Transaction State Diagram

Activeread / write PartiallyCommitted Committedsaved to disk Failedcannot continue Abortedrolled back Terminated
🟢
Happy path

Active → Partially Committed → Committed → Terminated.

🔴
Failure path

Active / Partially Committed → Failed → Aborted → Terminated.

Section 03 · Rules

Which Transitions Are Legal?

TransitionValid?Reason
Active → Partially CommittedYESAfter the final operation executes
Active → FailedYESCrash or error during execution
Partially Committed → CommittedYESChanges flushed to stable storage
Partially Committed → FailedYESThe final disk write can still fail
Committed → ActiveNOCommit is final — can't re-run it
Failed → CommittedNOA failed transaction must be aborted, never committed
🔒
The Iron Rule

"Committed is forever." A transaction can never go from Committed back to Active or Aborted — undoing it requires a brand-new compensating transaction.

Section 04

The Four ACID Properties

⚛️
Atomicity
All or nothing. Every step succeeds, or the whole transaction rolls back.
⚖️
Consistency
Valid → valid. No constraint, key, or balance rule is ever broken.
🚧
Isolation
No peeking. Concurrent transactions can't see each other's uncommitted work.
💾
Durability
Committed = forever. Changes survive crashes, power loss, and restarts.
🧠
Memory Hook — "A Cat In Danger"

Atomicity · Consistency · Isolation · Durability. Consistency is the goal; Atomicity, Isolation, and Durability are the mechanisms that achieve it.

Section 04 · Detail

Each Property, and Who Guarantees It

PropertyPromiseGuaranteed by
AtomicityAll operations succeed or none do — no partial executionTransaction / recovery manager
ConsistencyMoves DB from one valid state to another; totals add upApplication + DBMS
IsolationConcurrent result equals some serial orderConcurrency-control manager
DurabilityCommitted changes persist through any later crashRecovery manager (logs + stable storage)
🗺️
Symptom → Culprit

Partial execution → Atomicity. Broken rule / total mismatch → Consistency. Transactions seeing each other → Isolation. Committed data lost after a crash → Durability.

Section 05

Atomicity — Without vs With

❌ Without atomicity — crash mid-way
StepAB
Start100002000
Write(A)50002000
💥 CRASH50002000
Result50002000

Total 12,000 → 7,000. ₹5,000 vanished.

✅ With atomicity — rolled back
StepAB
Start100002000
Write(A)50002000
↺ ROLLBACK100002000
Result100002000

Total stays 12,000. Consistent state restored.

🛡️
Atomicity Protects Consistency

By undoing the half-finished transfer, atomicity guarantees the money supply stays balanced — the invariant "A + B is unchanged by a transfer" holds.

Concurrency

Why Run Transactions Concurrently?

⚡
The upside
Thousands of users share the database at once — higher throughput, better resource use, no one waiting in a single-file queue.
💥
The risk
Interleaved reads and writes can corrupt data unless the DBMS keeps transactions isolated from one another.
🎯
The Isolation Promise

A concurrent schedule is correct only if its outcome equals some serial execution of the same transactions. When it doesn't, one of the anomalies on the next slides has crept in.

Concurrency · Anomalies

Four Isolation Failures

🩹
Lost update
Two writes to the same item; the second overwrites the first with stale data.
🫥
Dirty read
One transaction reads another's uncommitted value — which may be rolled back.
🔁
Unrepeatable read
Re-reading the same row returns a different value because another commit changed it.
👻
Phantom read
A repeated query returns new rows that another transaction inserted.
🔧
All of These Are Isolation Failures

The cure is concurrency control — locking or timestamp ordering — forcing conflicting transactions to take turns.

Concurrency · Worked

The Lost Update, Step by Step

Both transactions increment X = 100 by 10. Expected final value: 120.

TimeT1T2X
t1Read(X) → 100100
t2Read(X) → 100100
t3X := 110100
t4Write(X)110
t5X := 110110
t6Write(X)110
🩹
What went wrong

T2 read X before T1 wrote it, so T2's write (110) overwrote T1's update. One of the two +10 increments simply disappeared.

✅
The fix

Proper isolation (locking) makes T2 wait until T1 commits — producing the correct 120.

🔢
Expected 120 · Actual 110

The gap of 10 is the "lost" update — a textbook Isolation violation.

Section 07

Rapid-Fire Concept Check

QuestionAnswer
Initial state of every transactionActive
State after final op, before disk writePartially Committed
All-or-nothing executionAtomicity
Committed data survives a crashDurability
Prevents concurrent interferenceIsolation
Keeps the database in a valid stateConsistency
Makes changes permanentCommit
Undoes all changesRollback / Abort
One update overwrites anotherLost Update
Section 08

Golden Rules of Transactions

🏆 NON-NEGOTIABLE PRINCIPLES
1
Transactions are atomic — no "half done" state exists. Never build logic that depends on partial completion.
2
Know the two paths: Active → Partially Committed → Committed, or → Failed → Aborted. Both end at Terminated.
3
"Committed is forever." Reversal requires a new compensating transaction, never a rollback.
4
Consistency is the goal; Atomicity, Isolation, and Durability are the mechanisms that achieve it.
5
Concurrency anomalies are Isolation failures — cure them with locking or timestamp ordering.
6
Durability relies on the write-ahead log — changes are logged to stable storage before commit is acknowledged.
FINAL

All or Nothing, Forever, In Isolation

1Indivisible unit
5Transaction states
ACIDFour guarantees
2Endings: commit / abort
🎯
Why It All Matters

A transaction bundles many operations into one all-or-nothing unit that travels a strict lifecycle from Active to Committed or Aborted. The ACID properties keep that unit safe: atomic, valid, isolated, and durable — so a crash mid-transfer or a race between users can never leave the database lying.

🧠
One Sentence to Remember

Consistency is the promise; Atomicity, Isolation, and Durability are how the DBMS keeps it — next stop: serializability and how schedules are proven safe.

💳 End of tutorial · Press ← to review, or click Restart