Timestamp ordering and validation
Use logical order and read-version evidence without mistaking clocks or a validation snapshot for a complete commit protocol.
On this page
The question for today
What you’ll understand
- Distinguish logical serialization timestamps from physical-clock readings.
- Trace a simple read-version validation rule and its atomicity boundary.
- Explain why distributed validation needs protection across all participating shards.
A transaction reads two records, computes a result, and finds that neither has changed when it checks. Can it now commit safely? Only if the validation protocol prevents another transaction from changing the relevant facts between that check and the protected commit. Timestamps help describe order; validation helps reject stale assumptions. Neither label removes the need to specify which concurrent operations can occur at each boundary.
Define what a timestamp orders
A timestamp can be a monotonically allocated logical label rather than a reading from a wall clock. A concurrency-control protocol may use it to select versions or enforce a serialization order. State when the label is assigned and what comparisons mean. Physical time introduces uncertainty and synchronization assumptions, especially across machines. Unrelated local counters cannot automatically be compared as one global order, while a total order alone does not prove that the transaction read versions consistent with that order.
Basic timestamp-ordering schemes maintain metadata such as the largest read and write timestamps associated with an item, rejecting operations that would violate the chosen order. Optimistic schemes instead often read first and validate later. These are related approaches with different rules, not interchangeable descriptions of one algorithm. A production design must specify handling of predicates, insertions, deletes, and blind writes as well as single-record updates. A transaction can violate an invariant through a changed query result even when none of the rows it happened to return was overwritten.
Close the validation-to-install gap
If two validators both inspect old state and then publish incompatible writes without coordination, each local check can pass while their combined execution is wrong. A correct protocol integrates validation with an ordering, locking, or certification mechanism that protects the intended serialization point. In a distributed transaction, that protection must cover the relevant participants. Collecting independently valid statements from different instants does not create one atomic global validation snapshot. Atomic commit still has to coordinate their final outcome.
Keep candidate writes private until the protocol authorizes publication, and preserve enough read or predicate metadata to validate the transaction’s actual decisions. On validation failure, restart the logical computation with new reads instead of repeatedly submitting the same stale write set. A useful conflict report identifies the record or predicate involved, observed and conflicting versions, and the validation phase. That evidence helps distinguish contention from a broken versioning implementation or an application that performed essential reads outside the transaction.
Clock bounds are one component of a larger design
Spanner combines clock uncertainty bounds with concurrency control, replication, and distributed commit. Its external-consistency argument is not merely that timestamps look like real time. When discussing such a system, identify how uncertainty is bounded, how a timestamp is selected, and when waiting establishes the required ordering relative to real-time completion. Do not transplant a commit-wait expression into a database that lacks the surrounding guarantees. Clock accuracy can affect waiting, but an accurate clock cannot repair a missing validation or atomic-commit step.
The queue lab illustrates validator capacity rather than certification correctness. Reset, set arrival rate to 4 and service rate to 3, predict backlog after one second, then Step twice. Start a separate run with Reset and both rates explicitly set to 2 and 3; predict before two Steps. Each starts with four units. The difference exposes queued validation work only. It does not model timestamp assignment, conflict graphs, clock uncertainty, or transaction decisions, so verify those properties with an explicit execution trace.
Work it through
Reject a stale read version
T reads record x at version 7 and y at version 12, then plans a write based on their sum. Before T’s protected validation stage, U changes y to version 13. Assume this toy validator requires exact read-version equality and closes its validation-to-install gap.
Write T’s read set as x:7 and y:12. Checking only the destination write record would miss the changed input y.
At validation, x remains version 7 but y is version 13. The equality test fails for one of the two required reads, so this validator rejects T.
Restart T with fresh reads and recompute its result. Reusing the old sum with a new transaction identifier would retain the stale assumption rather than fix it.
One changed input is enough to reject this toy transaction. The correctness claim also depends on the stated protected stage and complete read/predicate coverage.
The living notebook
Explore the model
Interactive lab · queue
Validation has a service capacity
Reset, set arrival rate λ = 4 and service rate μ = 3, predict backlog at one second, then Step twice. Compare a fresh Reset with both λ = 2 and μ = 3, predicting before two Steps. This fluid model illustrates validator work pressure, not timestamp or conflict validation.
- Fluid backlog
- 4
- Net rate · λ − μ
- −1 /s
- M/M/1 mean residence
- 1 s
Fluid backlog starts at 4 and follows max(0, 4 + (λ − μ)t). The separate M/M/1 residence-time formula assumes Poisson arrivals, exponential service and λ < μ. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.
Look forA fast or lightly queued validator still needs a correct certification and publication protocol.
Pause & reason
Check your understanding
Your turn
Try it yourself
A toy read set records versions a:4, b:9, c:2. Validation sees a:4, b:10, c:2. Count matching and mismatching records. Explain why deleting b from the read set after seeing the mismatch would invalidate the argument.
Take a moment to make a prediction or work it out on paper. Open a hint when you need one.
Give me a hint
The read set must describe the inputs that actually influenced the transaction.
Compare with the solution
Two records match and one, b, does not. Under the stated exact-version rule, validation fails. Removing b afterward would conceal a dependency rather than establish that it was irrelevant. The transaction must recompute from fresh inputs or follow a separately proved validation scheme that legitimately permits that change; it cannot edit its evidence solely to make certification succeed.
Keep the idea
Take it with you
- Timestamp meaning comes from a protocol rather than its numeric format.
- Read and predicate validation must connect safely to write publication.
- Clock bounds, replication, atomic commit, and isolation solve different parts of the design.
Read further
Original sources and deeper explanations to follow at your own pace.
Optional progress, saved in this browser when available. Revisit any lesson at any time.
Lesson not marked complete.