DEV Community

Cover image for How Databases Safely Ignore Obsolete Writes: Thomas Write Rule Explained
Binary Dose
Binary Dose

Posted on Originally published at binarydose.in

How Databases Safely Ignore Obsolete Writes: Thomas Write Rule Explained

How Databases Safely Ignore Obsolete Writes: Thomas Write Rule Explained

In distributed databases and concurrency control, standard locking mechanisms (like 2PL) can cause painful deadlock cycles and lock contention.

To solve this, database engines use Timestamp Ordering (TSO): transactions execute lock-free, ordered by logical timestamps TS(T).


⚡ The Standard Timestamp Ordering Conflict

For every data record Q, the database tracks two timestamps:

  • R-TS(Q): The largest timestamp of any transaction that read Q.
  • W-TS(Q): The largest timestamp of any transaction that wrote to Q.

Under standard Timestamp Ordering, when an older transaction T₁ (TS = 10) attempts to execute write(Q) after a newer transaction T₂ (TS = 20) has already updated Q:

Time ────────────────────────────────────────────────────────►
T1 (TS = 10) ──── attempts write(Q) ───► 💥 CONFLICT!
T2 (TS = 20) ──── already executed write(Q) [W-TS(Q) = 20]
Enter fullscreen mode Exit fullscreen mode

Standard TSO says:

"You are an older transaction attempting to overwrite a newer value. Abort and rollback T₁!"

Rolling back transactions wastes CPU cycles, bandwidth, and increases user latency.


🧠 The Thomas Write Rule Breakthrough

In 1979, Robert H. Thomas realized that under one specific condition, aborting T₁ is completely unnecessary:

IF:
   TS(T) < W-TS(Q)   (A newer transaction already wrote Q)
AND:
   TS(T) >= R-TS(Q)  (No transaction with TS > TS(T) has read Q!)

THEN:
   DO NOT ABORT T.
   SIMPLY IGNORE / DISCARD THE WRITE!
Enter fullscreen mode Exit fullscreen mode

Why Can We Safely Ignore the Write?

  1. The value that T₁ wanted to write was destined to be immediately overwritten by T₂ anyway.
  2. Because no intermediate transaction ever read T₁'s value, skipping T₁'s write produces the exact same final database state as if T₁ had executed first!
  3. T₁ continues executing without incurring a costly rollback.

🚀 View Serializability vs Conflict Serializability

Thomas Write Rule is famous in database theory because it generates schedules that are View Serializable but NOT Conflict Serializable:

Schedule S:
T1: read(A)                write(A) (ignored!)
T2:          write(A)
────────────────────────────────────────────────────────►
Result: Valid view-equivalent schedule without aborting T1!
Enter fullscreen mode Exit fullscreen mode

🛠️ Step Through the Live Simulator

Want to inspect timestamp comparisons, simulate out-of-order writes, and test Thomas Write Rule interactively?

👉 Step through the interactive concurrency schedule simulator on Binary Dose.

Top comments (0)