Skip to main content

Timestamp Ordering Protocol & Thomas Write Rule

📚Module 01Topic 1.1⏱️5 min read
🎯High-Yield For:Semester Exams • GATE CSE • Technical Interviews

💡 Core Intuition​

🍳 The Everyday Analogy: The Chronological Mail Sorting Office​

Imagine a postal sorting facility where every letter is stamped with an atomic timestamp as it enters the front door:

  • An elderly courier (ToldT_{\text{old}}, Timestamp 10:00 AM10:00\text{ AM}) walks in with a revised address for a package.
  • But looking at the package delivery log, the clerk notices that a young messenger (TyoungT_{\text{young}}, Timestamp 10:30 AM10:30\text{ AM}) has already picked up the package and shipped it out (R(Q)R(Q))!
  • The elderly courier is too late: their update arrived out of chronological order. Under strict protocol rules, the old letter is rejected and shredded.

Now, consider a different scenario:

  • The young messenger (TyoungT_{\text{young}}, Timestamp 10:30 AM10:30\text{ AM}) painted the shipping crate bright blue (W(Q)W(Q)).
  • A few minutes later, the elderly courier (ToldT_{\text{old}}, Timestamp 10:00 AM10:00\text{ AM}) arrives with a can of yellow paint intending to paint the crate yellow (W(Q)W(Q)).

Under strict rules, the clerk would scream and abort the old courier. But an astute clerk named Thomas observes: "Wait! The crate is already blue, and the blue paint was ordered at 10:30 AM10:30\text{ AM}. Even if we had painted it yellow at 10:00 AM10:00\text{ AM}, it would have been repainted blue 30 minutes later anyway! Let's just quietly ignore the yellow paint and let the courier go home successfully."

This common-sense optimization is Thomas' Write Rule: obsolete blind writes are harmlessly ignored, boosting performance without corrupting the final view.

💻 Bridging to Computer Science​

Unlike Two-Phase Locking (which uses locks and dynamic blocking), the Timestamp Ordering Protocol is an optimistic/non-locking concurrency protocol.

It predetermines the serialization order before transactions execute: Serialization Order ≡Chronological Inception Timestamp TS(Ti)\text{Serialization Order } \equiv \text{Chronological Inception Timestamp } TS(T_i)

Transaction Inception  --->  Assigned Monotonic Timestamp TS(Ti)
Item Q maintains: ---> W-timestamp(Q) and R-timestamp(Q)

Because transactions never wait for locks, deadlocks are mathematically impossible. If an operation arrives out of order, the transaction is immediately rolled back and restarted.



📚 Core Deep-Dive & Concepts​

Timestamps for Transactions & Data Items​

1. Transaction Timestamp TS(Ti)TS(T_i)​

When transaction TiT_i enters the system, the DBMS assigns it a unique, immutable timestamp:

  • Generated using the system clock or a monotonic logical counter.
  • If T1T_1 enters before T2T_2, then TS(T1)<TS(T2)TS(T_1) < TS(T_2) (T1T_1 is older, T2T_2 is younger).
  • The timestamp remains fixed throughout the transaction's lifetime.

2. Data Item Timestamps​

Every data item QQ in the database maintains two dynamic tracking timestamps:

  • W-timestamp(Q)\text{W-timestamp}(Q): The largest timestamp of any transaction that successfully executed a write operation Write(Q)\text{Write}(Q).
  • R-timestamp(Q)\text{R-timestamp}(Q): The largest timestamp of any transaction that successfully executed a read operation Read(Q)\text{Read}(Q).

Whenever a transaction successfully reads or writes QQ, the respective timestamp is updated to the maximum of its existing value and TS(Ti)TS(T_i).


The Basic Timestamp Ordering Protocol Rules​

Whenever transaction TiT_i issues a read or write request on data item QQ:

Read Protocol: TiT_i issues Read(Q)\text{Read}(Q)​

                TS(Ti) < W-timestamp(Q) ?
/ \
YES NO
/ \
[ REJECT & ROLLBACK Ti ] [ EXECUTE Read(Q) ]
R-timestamp(Q) = max(R-timestamp(Q), TS(Ti))
  1. If TS(Ti)<W-timestamp(Q)TS(T_i) < \text{W-timestamp}(Q): A younger transaction (with timestamp >TS(Ti)> TS(T_i)) has already overwritten QQ. Transaction TiT_i needs to read an older, overwritten value that has vanished.   ⟹  \implies Reject the read operation and ROLL BACK TiT_i!
  2. If TS(Ti)≥W-timestamp(Q)TS(T_i) \ge \text{W-timestamp}(Q): The write on QQ occurred before TiT_i's logical time.   ⟹  \implies Execute Read(Q)\text{Read}(Q) successfully, and update: R-timestamp(Q)=max⁡(R-timestamp(Q), TS(Ti))\text{R-timestamp}(Q) = \max\left(\text{R-timestamp}(Q), \, TS(T_i)\right)

Write Protocol: TiT_i issues Write(Q)\text{Write}(Q)​

  1. If TS(Ti)<R-timestamp(Q)TS(T_i) < \text{R-timestamp}(Q): A younger transaction has already read the value of QQ under the assumption that TiT_i's write would never happen.   ⟹  \implies Reject the write operation and ROLL BACK TiT_i!
  2. If TS(Ti)<W-timestamp(Q)TS(T_i) < \text{W-timestamp}(Q): A younger transaction has already overwritten QQ with a newer value. TiT_i is attempting to write an obsolete value.   ⟹  \implies Reject the write operation and ROLL BACK TiT_i! (Under Basic Timestamping).
  3. Otherwise (TS(Ti)≥R-timestamp(Q)TS(T_i) \ge \text{R-timestamp}(Q) AND TS(Ti)≥W-timestamp(Q)TS(T_i) \ge \text{W-timestamp}(Q)):   ⟹  \implies Execute Write(Q)\text{Write}(Q) successfully, and update: W-timestamp(Q)=max⁡(W-timestamp(Q), TS(Ti))\text{W-timestamp}(Q) = \max\left(\text{W-timestamp}(Q), \, TS(T_i)\right)

Thomas' Write Rule: Optimizing Obsolete Blind Writes​

In 1979, Robert H. Thomas observed that Condition 2 of the basic write protocol is overly restrictive.

Definition: Thomas' Write Rule is a modified timestamp ordering protocol that optimizes handling of obsolete blind writes:

When Ti attempts Write(Q) and TS(Ti)<W-timestamp(Q):\text{When } T_i \text{ attempts } \text{Write}(Q) \text{ and } \mathbf{TS(T_i) < \text{W-timestamp}(Q)}:

The Thomas Write Directive: Instead of rejecting the write and aborting TiT_i, SIMPLY IGNORE THE WRITE OPERATION AND PROCEED!

Why Ignoring the Write is Correct​

  1. Because TS(Ti)<W-timestamp(Q)TS(T_i) < \text{W-timestamp}(Q), a younger transaction TjT_j has already written to QQ.
  2. Because TS(Ti)≥R-timestamp(Q)TS(T_i) \ge \text{R-timestamp}(Q), no active transaction needed to read TiT_i's intermediate write value.
  3. Therefore, TiT_i's write is an obsolete intermediate value that would have been overwritten immediately by TjT_j anyway.
  4. By silently dropping TiT_i's write, the final state of QQ remains identical to the state produced by TjT_j.

Serializability Impact​

  • Basic Timestamp Ordering guarantees Conflict Serializability.
  • Thomas' Write Rule allows schedules that violate conflict order, but guarantees View Serializability!

The Master Concurrency Control Comparison Matrix​

The following table synthesizes the fundamental properties of all major database concurrency control protocols:

Concurrency ProtocolConflict Serializable?View Serializable?Recoverable by Default?Cascadeless (ACA)?Deadlock Free?
Basic Timestamp Protocol✅ Yes✅ Yes❌ No❌ No✅ Yes
Thomas Write Rule❌ No✅ Yes❌ No❌ No✅ Yes
Basic 2PL✅ Yes✅ Yes❌ No❌ No❌ No
Conservative 2PL✅ Yes✅ Yes❌ No❌ No✅ Yes
Strict 2PL✅ Yes✅ Yes✅ Yes✅ Yes❌ No
Rigorous 2PL✅ Yes✅ Yes✅ Yes✅ Yes❌ No

📐 Architecture / Visual Blueprint​

The following decision flowchart illustrates how a write request Write(Q)\text{Write}(Q) is processed under Basic Timestamping versus Thomas' Write Rule:


🏭 In The Real World: Production Case Study​

Distributed Key-Value Store: Apache Cassandra & ScyllaDB​

NoSQL distributed databases like Apache Cassandra, ScyllaDB, and DynamoDB handle petabytes of writes per second using Last-Write-Wins (LWW) conflict resolution—a direct industrial application of Thomas' Write Rule.

The LWW Production Scenario​

In globally distributed Cassandra clusters spanning multi-region datacenters:

  1. Client A updates user email: UPDATE users SET email = 'alice@new.com' at timestamp T=100T = 100.
  2. Due to WAN network congestion, Client A's packet is delayed in transit.
  3. Client B updates the same user email: UPDATE users SET email = 'alice@final.com' at timestamp T=105T = 105.
  4. Node 1 receives Client B's write first (W-ts=105W\text{-ts} = 105) and commits the record.
  5. Three seconds later, Client A's delayed packet (TS=100TS = 100) finally arrives at Node 1.

How Thomas' Write Rule Prevents Data Regression​

Under locking protocols, the node would have to acquire distributed locks or reject the connection. Instead, Cassandra evaluates Thomas' Write Rule: TS(Packet A)=100<W-timestamp(Record)=105TS(\text{Packet A}) = 100 < W\text{-timestamp}(\text{Record}) = 105 Cassandra silently discards the obsolete write payload. It acknowledges the write as successful without modifying the disk block, ensuring that older out-of-order network packets never overwrite newer committed data.


🎯 Exam & Interview Pitfall Check​

Core Conceptual Questions

Question 1: Explain why the Timestamp Ordering Protocol is inherently free from deadlocks.

Answer: A deadlock requires transactions to be trapped in a circular waiting dependency (Wait-For\text{Wait-For} cycle). In the Timestamp Ordering Protocol, transactions never wait for resources. When an operation is requested:

  • If the operation is chronologically valid with respect to data timestamps, it is executed immediately.
  • If the operation is out of order, the requesting transaction is immediately rejected and rolled back.

Because there is zero waiting, directed wait edges cannot form, rendering deadlocks mathematically impossible.


Question 2: Why is a schedule generated by Thomas' Write Rule view serializable, even if it is not conflict serializable?

Answer: Thomas' Write Rule permits an obsolete write (TS(Ti)<W-timestamp(Q)TS(T_i) < \text{W-timestamp}(Q)) to be safely ignored because a younger transaction TjT_j (TS(Tj)>TS(Ti)TS(T_j) > TS(T_i)) has already overwritten the data item, and no transaction read TiT_i's intermediate write value. In the conflict precedence graph, skipping the write inverts the expected write-write conflict edge, creating a cycle. However, in terms of View Equivalence:

  • Initial reads are preserved.
  • Data flows (updated reads) are preserved.
  • The final write is still executed by the younger transaction TjT_j.

Because all three view invariants remain identical to the serial timestamp order, the schedule is strictly View Serializable.

Common Interview Traps

Trap 1: Believing that Timestamp Ordering eliminates all concurrency overhead. While Timestamp Ordering avoids locking and deadlocks, it can suffer from severe Starvation (Livelock) under high write contention. Long-running transactions are repeatedly aborted and restarted whenever newer short transactions update timestamps ahead of them.

Trap 2: Assuming Thomas' Write Rule ignores reads as well. Thomas' Write Rule applies exclusively to Write operations where TS(Ti)<W-timestamp(Q)TS(T_i) < \text{W-timestamp}(Q). It does not ignore out-of-order read operations (TS(Ti)<W-timestamp(Q)TS(T_i) < \text{W-timestamp}(Q)). An obsolete read must always cause a transaction rollback to prevent reading dirty or fabricated data.


💬

Discussion & Doubts