Timestamp Ordering Protocol & Thomas Write Rule
💡 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 (, Timestamp ) walks in with a revised address for a package.
- But looking at the package delivery log, the clerk notices that a young messenger (, Timestamp ) has already picked up the package and shipped it out ()!
- 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 (, Timestamp ) painted the shipping crate bright blue ().
- A few minutes later, the elderly courier (, Timestamp ) arrives with a can of yellow paint intending to paint the crate yellow ().
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 . Even if we had painted it yellow at , 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:
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
When transaction enters the system, the DBMS assigns it a unique, immutable timestamp:
- Generated using the system clock or a monotonic logical counter.
- If enters before , then ( is older, is younger).
- The timestamp remains fixed throughout the transaction's lifetime.
2. Data Item Timestamps
Every data item in the database maintains two dynamic tracking timestamps:
- : The largest timestamp of any transaction that successfully executed a write operation .
- : The largest timestamp of any transaction that successfully executed a read operation .
Whenever a transaction successfully reads or writes , the respective timestamp is updated to the maximum of its existing value and .
The Basic Timestamp Ordering Protocol Rules
Whenever transaction issues a read or write request on data item :
Read Protocol: issues
TS(Ti) < W-timestamp(Q) ?
/ \
YES NO
/ \
[ REJECT & ROLLBACK Ti ] [ EXECUTE Read(Q) ]
R-timestamp(Q) = max(R-timestamp(Q), TS(Ti))
- If : A younger transaction (with timestamp ) has already overwritten . Transaction needs to read an older, overwritten value that has vanished. Reject the read operation and ROLL BACK !
- If : The write on occurred before 's logical time. Execute successfully, and update:
Write Protocol: issues
- If : A younger transaction has already read the value of under the assumption that 's write would never happen. Reject the write operation and ROLL BACK !
- If : A younger transaction has already overwritten with a newer value. is attempting to write an obsolete value. Reject the write operation and ROLL BACK ! (Under Basic Timestamping).
- Otherwise ( AND ): Execute successfully, and update:
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:
The Thomas Write Directive: Instead of rejecting the write and aborting , SIMPLY IGNORE THE WRITE OPERATION AND PROCEED!
Why Ignoring the Write is Correct
- Because , a younger transaction has already written to .
- Because , no active transaction needed to read 's intermediate write value.
- Therefore, 's write is an obsolete intermediate value that would have been overwritten immediately by anyway.
- By silently dropping 's write, the final state of remains identical to the state produced by .
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 Protocol | Conflict 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 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:
- Client A updates user email:
UPDATE users SET email = 'alice@new.com'at timestamp . - Due to WAN network congestion, Client A's packet is delayed in transit.
- Client B updates the same user email:
UPDATE users SET email = 'alice@final.com'at timestamp . - Node 1 receives Client B's write first () and commits the record.
- Three seconds later, Client A's delayed packet () 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: 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
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 ( 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 () to be safely ignored because a younger transaction () has already overwritten the data item, and no transaction read '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 .
Because all three view invariants remain identical to the serial timestamp order, the schedule is strictly View Serializable.
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 . It does not ignore out-of-order read operations (). An obsolete read must always cause a transaction rollback to prevent reading dirty or fabricated data.