DBMS 📂 Transactions and Concurrency: · 2 of 6 38 min read

Serializability in DBMS: Conflict Serializable Schedules

A complete tutorial on conflict serializability covering schedules (serial, non-serial, serializable), the three conditions for conflicting operations, conflict equivalence via swapping, and the precedence graph test with cycle detection and topological ordering. Includes three fully worked numericals, a schedule-counting formula problem, ASCII precedence-graph diagrams, an academic vs industry comparison (2PL, MVCC/SSI, isolation levels, retry-on-failure).

Section 01

The Story That Explains Serializability

Two Chefs, One Kitchen
Imagine two chefs sharing one kitchen. Chef T1 is baking a cake and Chef T2 is making soup. If each chef worked alone, one after the other, the results would be perfect every time — that is a serial schedule. But it's slow: the kitchen sits half-idle.

So they interleave: T1 uses the oven while T2 chops vegetables. Most interleavings are fine. Trouble starts only when they touch the same ingredient and at least one of them changes it — say T2 adds salt to a stock pot that T1 has already tasted and adjusted. Now the result depends on who touched it when.

Serializability asks one question: can this interleaved schedule produce the same result as some serial one? If yes, the schedule is safe — we get concurrency and correctness.

A schedule is a chronological order of operations from multiple transactions executing together. A schedule is serializable if its effect on the database is equivalent to that of some serial schedule of the same transactions. The most widely used and easily testable form is conflict serializability.

🤝
Why We Care (Both Worlds)

Academic view: serializability is the formal correctness criterion for concurrent execution — the gold standard against which isolation is defined. Industry view: it is what your database's SERIALIZABLE isolation level promises, and what lock managers and MVCC engines work hard to approximate without killing throughput.


Section 02

Schedules — Serial, Non-Serial, and the Trade-off

🚧
Serial Schedule
One at a time
Transactions execute back-to-back with no interleaving (T1 fully, then T2 fully). Always correct, never anomalous — but wastes CPU and I/O parallelism. With n transactions there are n! possible serial schedules.
🔀
Non-Serial Schedule
Interleaved
Operations of different transactions are mixed. Fast, exploits concurrency — but some interleavings corrupt data (lost updates, dirty reads). Only some of them are safe.
Serializable Schedule
Best of both
A non-serial schedule whose outcome equals some serial schedule. It gives the speed of interleaving with the safety of serial execution. This is the target.
💡
Key Relationship

Every serial schedule is serializable. Every conflict-serializable schedule is serializable. But not every serializable schedule is conflict-serializable (that wider class is view serializability — correct but NP-hard to test, which is why real systems and exams focus on the conflict form).


Section 03

Conflicting Operations — The Heart of It All

Two operations conflict if and only if all three conditions hold at once:

⚔️ The Three Conditions for a Conflict
Cond 1
They belong to different transactions.
Cond 2
They access the same data item.
Cond 3
At least one is a Write.
Pair (same item X, different txns)Conflict?NameWhy
Read(X) … Read(X)NOOrder of two reads never changes any result.
Read(X) … Write(X)YESRW conflictSwap them and the read sees a different value.
Write(X) … Read(X)YESWR conflictThe read depends on whether the write came first.
Write(X) … Write(X)YESWW conflictThe final value depends on which write is last.
⚠️
Common Exam Trap

Operations on different data items never conflict, and two operations of the same transaction never conflict (their order is fixed by the program anyway). Read–Read on the same item is the only same-item, different-transaction pair that is safe.


Section 04

Conflict Equivalence & Conflict Serializability

Two schedules are conflict equivalent if one can be transformed into the other by swapping only adjacent non-conflicting operations. A schedule is conflict serializable if it is conflict equivalent to some serial schedule.

Mini Numerical — Proving Equivalence by Swapping

Schedule S over items X and Y (subscripts show the transaction):

Schedule S (interleaved)
R1(X) W1(X) R2(X) R1(Y) W2(X) W1(Y)
🔄 Swap Steps (only non-conflicting adjacent pairs)
Swap 1
R1(Y) and R2(X): different items → no conflict → swap. Gives: R1(X) W1(X) R1(Y) R2(X) W2(X) W1(Y)
Swap 2
W1(Y) and W2(X): different items → swap. Then W1(Y) and R2(X): different items → swap.
Result
R1(X) W1(X) R1(Y) W1(Y) R2(X) W2(X) — this is the serial schedule T1 → T2. Hence S is conflict serializable. ✅

Swapping works for proofs, but it is slow for big schedules. The standard fast test is the precedence graph.


Section 05

The Precedence Graph (Serialization Graph) Test

01
Draw One Node per Transaction
For a schedule over T1, T2, T3 → three nodes. Nothing else.
02
Add an Edge Ti → Tj for Every Conflict
If an operation of Ti conflicts with a LATER operation of Tj (RW, WR, or WW on the same item), draw a directed edge Ti → Tj. Duplicate edges collapse into one.
03
Check for a Cycle
No cycle → conflict serializable. Any cycle → NOT conflict serializable. This check is linear-time — cheap enough for theory and practice.
04
Read Off the Serial Order (Topological Sort)
If acyclic, any topological ordering of the nodes is an equivalent serial schedule. Edge Ti → Tj means "Ti must come before Tj".

Section 06

Numerical 1 — A Serializable Schedule (Full Working)

Test schedule S1 for conflict serializability:

Schedule S1 — time runs left to right
t1 t2 t3 t4 t5 t6 T1: R1(A) W1(A) R1(B) W1(B) T2: R2(A) W2(A)
🧮 Step 1 — List Every Conflict Pair
Pair 1
W1(A) at t2 before R2(A) at t3 — WR conflict on A → edge T1 → T2
Pair 2
R1(A) at t1 before W2(A) at t4 — RW conflict on A → edge T1 → T2 (already exists)
Pair 3
W1(A) at t2 before W2(A) at t4 — WW conflict on A → edge T1 → T2 (already exists)
Item B
Only T1 touches B → no conflicts, no edges.
Step 2 — Precedence Graph (Numerical 1)
A: WR, RW, WW T1 T2

A single edge T1 → T2 — no cycle possible with only one arrow.

Verdict — Conflict Serializable

The graph is acyclic, so S1 is conflict serializable. Topological order: T1 → T2. The interleaved schedule behaves exactly like running T1 completely, then T2 completely.


Section 07

Numerical 2 — A Non-Serializable Schedule (The Cycle)

Now test schedule S2:

Schedule S2 — time runs left to right
t1 t2 t3 t4 T1: R1(X) W1(X) T2: R2(X) W2(X)

This is exactly the lost update pattern from your transactions tutorial — both transactions read X, then both write it. Let's prove formally why it is unsafe.

🧮 Conflict Pairs
Pair 1
R1(X) at t1 before W2(X) at t3 — RW → edge T1 → T2
Pair 2
R2(X) at t2 before W1(X) at t4 — RW → edge T2 → T1
Pair 3
W2(X) at t3 before W1(X) at t4 — WW → edge T2 → T1 (already exists)
Precedence Graph — Numerical 2 (Cycle!)
X: RW X: RW, WW T1 T2

Two opposing arrows on the same pair of nodes — T1 → T2 and T2 → T1 — form a cycle. Instant rejection.

Verdict — NOT Conflict Serializable

The cycle T1 → T2 → T1 means T1 must come both before and after T2 in any equivalent serial order — impossible. No serial schedule matches S2, so a DBMS enforcing serializability must block or abort one of these transactions (this is precisely when you see deadlock victims or serialization-failure errors in practice).


Section 08

Numerical 3 — Three Transactions (Exam Level)

Test schedule S3 over three transactions and two items:

Schedule S3
t1 t2 t3 t4 t5 t6 T1: R1(X) W1(Y) T2: R2(Y) W2(X) T3: R3(X) W3(Y)
🧮 Systematic Conflict Hunt (item by item)
Item X
Ops in time order: R1(X), R3(X), W2(X). Conflicts: R1(X)–W2(X) → T1 → T2; R3(X)–W2(X) → T3 → T2. (R1–R3 is read–read: no edge.)
Item Y
Ops in time order: R2(Y), W1(Y), W3(Y). Conflicts: R2(Y)–W1(Y) → T2 → T1; R2(Y)–W3(Y) → T2 → T3; W1(Y)–W3(Y) → T1 → T3.
Edges
T1→T2, T3→T2, T2→T1, T2→T3, T1→T3
Precedence Graph — Numerical 3 (Multiple Cycles)
X: RW Y: RW Y: WW Y: RW X: RW T1 T2 T3

Red arrows highlight two cycles: T1 ↔ T2 (top) and T2 ↔ T3 (right side). Either alone is enough to reject.

Verdict — NOT Conflict Serializable

The two-node cycle T1 → T2 → T1 already settles it (the larger cycle T2 → T3 → T2 exists too). One cycle is enough — you can stop searching the moment you find the first one.

Speed Technique for Exams

Go item by item, list that item's operations in time order, and draw edges only between pairs where at least one is a Write. This is faster and far less error-prone than scanning the whole schedule left to right.


Section 09

Solved Examples — Schedule Tables & Precedence Graph Diagrams

In exams and textbooks, schedules are usually presented as a table (one column per transaction, time flowing downward) and the answer is justified with a drawn precedence graph. Here are three fully solved examples in exactly that format.

Example 1 — Three Transactions, Three Items (Serializable)

Problem: Check whether the given schedule S is conflict serializable or not.

Schedule S
S: R1(x), R3(y), R3(x), R2(y), R2(z), W3(y), W2(z), R1(z), W1(x), W1(z)
Time Transaction 1 Transaction 2 Transaction 3
t1R(x)
t2R(y)
t3R(x)
t4R(y)
t5R(z)
t6W(y)
t7W(z)
t8R(z)
t9W(x)
t10W(z)
🧮 Conflict Hunt — Item by Item
Item x
R1(x) @t1, R3(x) @t3, W1(x) @t9. Conflict: R3(x) before W1(x) — RW → edge T3 → T1. (R1–R3 is read–read; R1(x)–W1(x) is the same transaction — no edges.)
Item y
R3(y) @t2, R2(y) @t4, W3(y) @t6. Conflict: R2(y) before W3(y) — RW → edge T2 → T3.
Item z
R2(z) @t5, W2(z) @t7, R1(z) @t8, W1(z) @t10. Conflicts: W2(z)R1(z) (WR), R2(z)W1(z) (RW), W2(z)W1(z) (WW) — all give the same edge T2 → T1.
Edges
T2 → T1,   T2 → T3,   T3 → T1
Precedence Graph — Example 1
z: WR,RW,WW y: RW x: RW T1 T2 T3

Edges: T2 → T1 (item z), T2 → T3 (item y), T3 → T1 (item x). All arrows flow one way — no path returns to its starting node.

Verdict — Conflict Serializable

There is no cycle in the precedence graph, so S is conflict serializable. T2 has no incoming edges, then T3, then T1 — equivalent serial schedule: T2 → T3 → T1.

Equivalent Serial Schedule (T2 → T3 → T1)
R2(y), R2(z), W2(z), R3(y), R3(x), W3(y), R1(x), R1(z), W1(x), W1(z)

Example 2 — The Cycle Trap (NOT Serializable)

Problem: Check whether schedule S is conflict serializable:

Schedule S
S: R1(x), R2(y), W2(x), W1(y), R3(z), W3(z)
Time Transaction 1 Transaction 2 Transaction 3
t1R(x)
t2R(y)
t3W(x)
t4W(y)
t5R(z)
t6W(z)
🧮 Conflict Hunt — Item by Item
Item x
R1(x) @t1 before W2(x) @t3 — RW → edge T1 → T2
Item y
R2(y) @t2 before W1(y) @t4 — RW → edge T2 → T1
Item z
R3(z) and W3(z) both belong to T3 — same transaction, no edge. T3 stays isolated.
Edges
T1 → T2 and T2 → T1 — a two-node cycle.
Precedence Graph — Example 2 (Cycle!)
x: RW y: RW ⟳ CYCLE: T1 → T2 → T1 T1 T2 T3 (isolated — no edges)

T3 only touches item z, so it has no edges — but an isolated node cannot save the schedule. One cycle anywhere is enough to reject.

Verdict — NOT Conflict Serializable

The cycle T1 → T2 → T1 means T1 must come both before and after T2 in any serial order — impossible. No equivalent serial schedule exists. Note that T3 being conflict-free is irrelevant: the verdict is decided the moment a cycle appears.

Example 3 — Two Valid Serial Orders (Serializable)

Problem: Check whether schedule S is conflict serializable, and give all equivalent serial schedules:

Schedule S
S: R2(a), R1(b), W2(a), R1(a), R3(b), W1(b)
Time Transaction 1 Transaction 2 Transaction 3
t1R(a)
t2R(b)
t3W(a)
t4R(a)
t5R(b)
t6W(b)
🧮 Conflict Hunt — Item by Item
Item a
R2(a) @t1, W2(a) @t3, R1(a) @t4. Conflict: W2(a) before R1(a) — WR → edge T2 → T1. (R2(a)–W2(a) is the same transaction.)
Item b
R1(b) @t2, R3(b) @t5, W1(b) @t6. Conflict: R3(b) before W1(b) — RW → edge T3 → T1. (R1–R3 is read–read.)
Edges
T2 → T1 and T3 → T1. No edge between T2 and T3.
Precedence Graph — Example 3
a: WR b: RW T2 T3 T1

Both edges point INTO T1, and T2/T3 are unconnected to each other — so T1 must come last, but T2 and T3 can come in either order.

Verdict — Conflict Serializable, TWO Valid Orders

The graph is acyclic, so S is conflict serializable. Because T2 and T3 have no edge between them, the topological sort gives two equally correct serial schedules: T2 → T3 → T1 and T3 → T2 → T1. In an exam, naming either one (or both) earns full marks.

💡
Pattern Recognition Across the Three Examples

Example 1: a one-way triangle → exactly one serial order. Example 2: any two-way pair of arrows → instant rejection, regardless of other nodes. Example 3: unconnected nodes → multiple valid serial orders. Most exam questions are a variation of one of these three graph shapes.


Section 10

Counting Schedules — A Classic Numerical

Question: Transactions T1 and T2 have m = 3 and n = 2 operations respectively. How many total schedules are possible, and how many are serial?

Total Schedules
(m+n)! / (m! × n!)
Choose which of the m+n time slots belong to T1; internal order within each transaction is fixed by its program.
Serial Schedules
k!  (k = number of transactions)
All orderings of whole transactions run back-to-back. For 2 transactions: 2! = 2 (T1T2 and T2T1).
✅ Solution
Total
(3+2)! / (3! × 2!) = 120 / 12 = 10 possible schedules
Serial
2! = 2 serial schedules (T1→T2 and T2→T1)
Non-serial
10 − 2 = 8 non-serial schedules, of which only some will be conflict serializable — each must be tested with a precedence graph.

Section 11

Academic View vs Industry View

🎓 Academic Lens
ConcernTreatment
CorrectnessFormal: equivalence to a serial schedule
TestPrecedence graph + cycle detection
Theory classesConflict ⊂ View ⊂ Serializable
Exam focusDraw graph, find cycle, topological order
🏭 Industry Lens
ConcernTreatment
ThroughputSerializable is safest but slowest level
Mechanism2PL locking, MVCC / SSI, timestamps
Default levelsOften Read Committed / Repeatable Read
Failure modeRetry on serialization-failure errors

In practice, engines do not test schedules after the fact — they prevent non-serializable interleavings as they happen. Two-Phase Locking (2PL) guarantees conflict-serializable schedules by construction, while modern MVCC engines (e.g. PostgreSQL's Serializable Snapshot Isolation) monitor dangerous read-write dependency patterns and abort one transaction when a potential cycle appears. The application is expected to catch that error and retry the transaction — an industry habit every backend developer needs.

📊
The Engineering Trade-off

Stricter isolation → fewer anomalies but more blocking/aborts and lower throughput. Weaker isolation → faster, but the burden of reasoning about anomalies shifts to your application code. Serializability is the only level where you never have to reason about interleavings at all.


Section 12

Rapid-Fire Concept Check

QuestionAnswer
Two reads on the same item by different transactions — conflict?No (only pair with no Write)
Test used for conflict serializabilityPrecedence (serialization) graph
Graph has a cycle — verdict?Not conflict serializable
Graph is acyclic — how to get the serial order?Topological sort
Edge Ti → Tj meansTi must precede Tj serially
Number of serial schedules for k transactionsk!
Equivalence allowing swaps of non-conflicting adjacent opsConflict equivalence
Broader class, NP-hard to testView serializability
Protocol that guarantees conflict-serializable schedulesTwo-Phase Locking (2PL)
Every conflict-serializable schedule is also…View serializable (not vice versa)

Section 13

Golden Rules

🤝 Conflict Serializability — Non-Negotiable Rules
1
A conflict needs all three: different transactions, same data item, at least one Write. Miss any one condition and there is no conflict and no edge.
2
The precedence-graph test is mechanical: nodes = transactions, edges = conflicts (earlier op → later op's transaction), cycle = not serializable. Never draw nodes for data items.
3
One cycle is enough to reject. Stop as soon as you find it. Conversely, you must check all conflict pairs before declaring a schedule serializable.
4
Hunt conflicts item by item, not line by line. List each item's operations in time order and pair up everything involving a Write.
5
An acyclic graph's topological order is your answer to "give an equivalent serial schedule". If multiple topological orders exist, all of them are valid answers.
6
Remember the hierarchy: Serial ⊂ Conflict Serializable ⊂ View Serializable ⊂ All Schedules. Conflict serializability is preferred because its test runs in polynomial time; the view test is NP-hard.
7
Industry reality: databases prevent rather than test — via 2PL or SSI — and may abort your transaction to break a cycle. Always write application code that retries on serialization failures.