Serializability ensures that concurrent transactions produce the same result as if they were executed one after another (serially). It guarantees data consistency even with multiple transactions running simultaneously.
Two transactions (T1 and T2) transferring money between accounts:
Initial balances:
BEGIN TRANSACTION;
UPDATE Accounts SET balance = balance - 100 WHERE id = 'A';
UPDATE Accounts SET balance = balance + 100 WHERE id = 'B';
COMMIT;
BEGIN TRANSACTION;
UPDATE Accounts SET balance = balance - 200 WHERE id = 'B';
UPDATE Accounts SET balance = balance + 200 WHERE id = 'A';
COMMIT;
| Time | T1 | T2 | A | B |
|---|---|---|---|---|
| 1 | UPDATE A = A - 100 (A=900) | 900 | 1000 | |
| 2 | UPDATE B = B - 200 (B=800) | 900 | 800 | |
| 3 | UPDATE B = B + 100 (B=900) | 900 | 900 | |
| 4 | UPDATE A = A + 200 (A=1100) | 1100 | 900 |
Result: B = $900 (Expected: $1000) ❌ Inconsistency!
Problem: Lost Update - T2's deduction was overwritten by T1's addition.
The database ensures transactions run as if in sequence (T1 → T2 or T2 → T1).
| Time | T1 | T2 | A | B |
|---|---|---|---|---|
| 1 | A = A - 100 (A=900) | 900 | 1000 | |
| 2 | B = B + 100 (B=1100) | 900 | 1100 | |
| 3 | COMMIT | 900 | 1100 | |
| 4 | B = B - 200 (B=900) | 900 | 900 | |
| 5 | A = A + 200 (A=1100) | 1100 | 900 | |
| 6 | COMMIT | 1100 | 900 |
Result: A = $1100, B = $900 ✅ Correct
Conflict Serializability ensures concurrent execution matches some serial execution of the same transactions.
A schedule is conflict-serializable if it can be transformed into a serial schedule by swapping non-conflicting operations while maintaining the order of conflicting operations.
Two operations conflict if:
| Condition | Description | Example |
|---|---|---|
| 1 | Different transactions | T1 and T2 (not same transaction) |
| 2 | Same data item | Both work on variable 'A' |
| 3 | At least one write | Read-Write, Write-Read, Write-Write |
| Operation Pair | Conflict? | Type | Explanation |
|---|---|---|---|
| Read-Read | No | Non-conflict | Multiple reads don't change data |
| Read-Write | Yes | Conflict | Read might use stale data |
| Write-Read | Yes | Conflict | Read depends on write order |
| Write-Write | Yes | Conflict | Final value depends on order |
Schedule: T1:R(X), T2:W(X), T1:W(X), T2:R(Y)
Conflicts: T1:R(X) → T2:W(X) and T2:W(X) → T1:W(X)
Precedence graph: T1 → T2 → T1 (cycle → not serializable)
Schedule S:
| Conflict | Operation 1 | Operation 2 | Type | Dependency |
|---|---|---|---|---|
| 1 | T1: Write(C) | T3: Read(C) | Write-Read | T3 → T1 |
| 2 | T2: Write(B) | T3: Write(B) | Write-Write | T3 → T2 |
| 3 | T1: Read(A) | T2: Read(A) | Read-Read | No conflict |
The schedule is NOT conflict-serializable because:
Modified Schedule S':
Equivalent Serial Schedule: T2 → T3 → T1
Verification: