Skip to content

Part 4 · Blueprint 20

Time, Clocks & Distributed Ordering: Lamport to TrueTime

13 min reading · Sources · Editorial review pending

Clock readings do not establish causality or a globally agreed execution order.

More
20px
Reading list
Page details

Published date · Last edited:

Draft edition. Editorial review and supplementary reading recommendations are still being completed.

Format: Architecture walkthrough. Prerequisites: the beginner bootcamp. Chapter prerequisites: Consistency Models: CAP, PACELC & Linearizability, Distributed Consensus: Raft & Multi-Paxos.

Sixty-second mental model

Problem: Clock readings do not establish causality or a globally agreed execution order.

Use: Choose elapsed time, causal order or total order explicitly.

Design boundary: Distinguish physical timestamps, causal order and an agreed total order. Clock synchronization has error bounds and failures. A timestamp alone does not prove that an observed event happened before another across machines.

Layer 1 · Intuition

Hypothetical scenario: Northwind is designing time and ordering. Maya represents product requirements, Dev implementation and Priya reliability. The team must agree what one event means and which component owns the causal information.

Think of offices comparing wall clocks with numbered envelopes. Separate the requester from causal information, then identify the retained evidence needed after failure.

Authority
The entitled state owner.
Invariant
A rule preserved across concurrency and failures.

Architecture and worked reasoning

Design boundary: Distinguish physical timestamps, causal order and an agreed total order. Clock synchronization has error bounds and failures. A timestamp alone does not prove that an observed event happened before another across machines.

Responsibilities on the request path

Time and ordering: responsibilities and request directionDistinguish physical timestamps, causal order and an agreed total order. Clock synchronization has error bounds and failures. A timestamp alone does not prove that an observed event happened before another across machines.Event originLogical clockPartition logCausal reader
Distinguish physical timestamps, causal order and an agreed total order. Clock synchronization has error bounds and failures. A timestamp alone does not prove that an observed event happened before another across machines.

Workload and limiting resource

Hypothetical clocks can each differ from reference time by ±5 ms. Two observed timestamps 6 ms apart do not prove real order, because the uncertainty intervals can overlap. A scalar logical clock orders causal predecessors before successors, but the reverse inference is invalid: a smaller scalar timestamp need not mean a causal predecessor.

Keep the units attached to each intermediate result. The assumptions above describe a hypothetical exercise, not observed vendor capacity. A real capacity decision also needs a measured service curve, skew, recovery traffic and an explicit admission policy for overload.

Mutation or publication path

Time and ordering: mutation boundaryAttach identity and the relevant ordering metadata. Then: Advance logical clocks according to observed causality. Then: Choose a sequencer only for operations that need a shared total order.Step 1
Attach identity and the relevant ordering metadata.
Step 2
Advance logical clocks according to observed causality.
Step 3
Choose a sequencer only for operations that need a shared total order.
Attach identity and the relevant ordering metadata. Then: Advance logical clocks according to observed causality. Then: Choose a sequencer only for operations that need a shared total order.
  1. Attach identity and the relevant ordering metadata.
  2. Advance logical clocks according to observed causality.
  3. Choose a sequencer only for operations that need a shared total order.

Observation and recovery path

Time and ordering: observation boundaryCompare revisions using the declared rule. Then: Treat concurrent updates as concurrent rather than inventing causality. Then: Retain enough metadata to resolve or surface conflict.Step 1
Compare revisions using the declared rule.
Step 2
Treat concurrent updates as concurrent rather than inventing causality.
Step 3
Retain enough metadata to resolve or surface conflict.
Compare revisions using the declared rule. Then: Treat concurrent updates as concurrent rather than inventing causality. Then: Retain enough metadata to resolve or surface conflict.
  1. Compare revisions using the declared rule.
  2. Treat concurrent updates as concurrent rather than inventing causality.
  3. Retain enough metadata to resolve or surface conflict.

Failure that changes the decision

Hypothetical scenario: A wall clock moves backwards and a last-write-wins policy discards a later user edit. Choose version/causal semantics that match the domain and handle clock rollback explicitly.

Attempt this decision before reading the explanation

Can sorting UUIDs or wall timestamps recover the exact causal history?

No. Identifier structure or physical time can be useful, but causal dependence needs evidence of observation/message relationships, and concurrent events may have no causal order.

Supporting mechanism analysis

Hypothetical scenario: Northwind. Maya represents product, Dev implementation and Priya reliability. The following workflow develops the underlying mechanism.

Hypothetical scenario. Northwind retries a cleanup occurrence while an older product update is redelivered. Dev gives each attempt a new timestamp-based identifier and sorts the records. Priya can no longer tell which attempts belong to the same obligation.

This separates unique names from causal histories and chosen total order. The worked identifier space makes the generation assumptions visible without treating them as a complete protocol.

For a search projection, the selected operation can be identified by product identity, source version and projection schema version. Delivering that operation again does not create another product edit. A new projection schema version can represent genuinely different work even when it reads the same source version.

A central sequence can allocate distinct numbers within its coordinated scope. Independent generators can avoid that immediate dependency by using an appropriate identifier scheme, but they introduce assumptions about generation, namespace and collision handling. A random-looking label is not an explanation of those assumptions.

For UUID version 4, the format reserves four version bits and two variant bits within the 128-bit representation, leaving 128 − 4 − 2 = 122 random bits in the specified layout. That describes the format; correct generation and collision policy still matter. Do not replace those requirements with an unsupported claim of mathematical impossibility.

A sends after a, giving send event s scalar 2 and vector [2,0]. B receives s after b. Updating by the receive rules gives scalar max(1,2) + 1 = 3 and vector [2,2], counting B's receive event. Now s precedes that receive causally. The vectors [1,0] and [0,1] remain incomparable componentwise, exposing the original concurrency.

Hypothetical worked example. Choose a toy eight-bit random namespace, giving 2⁸ = 256 possible values. Draw ten identifiers independently and uniformly, allowing repeats. The number of distinct pairs of draws is 10 × 9 ÷ 2 = 45.

The toy namespace is intentionally small enough to inspect. It is not a risk estimate for correctly generated UUIDs. Its purpose is to expose which assumption a random-identifier argument uses and why an expected count must not be mislabeled as a measured failure percentage.

An event can causally precede another when local execution order or a communication path carries information from the first to the second. A send precedes its matching receive in that relationship. Two events with no such dependency may be concurrent even when their wall-clock fields look different.

Hypothetical scenario. Northwind’s two projection writers A and B start with vector [0, 0]. Each component counts events observed from its corresponding writer. Before a local event, a writer increments its own component. A’s edit-and-send event a receives [1, 0]; independently, B’s edit b receives [0, 1]. Neither vector is componentwise less than or equal to the other. Under this fixed-writer model, the edits are concurrent: neither carries evidence of observing the other.

The Cambridge distributed-systems notes, section 4.1 explain vector clocks alongside Lamport clocks. This exercise assumes distinct, stable writer identities and that the vector accompanies every modeled communication. Dropping causal dependencies or reusing a component after a restart can invalidate the comparison. A variable writer population also needs a representation and retirement policy; a two-entry vector is not an unrestricted production format.

Choose scalar ordering when that is all the operation needs. Pay for causal metadata when distinguishing observed succession from concurrency changes the result. A hybrid logical clock combines physical-time information with a logical component; its convenient ordering still does not supply a vector’s concurrency evidence. Keep source versions and authority checks separate from every timestamp format.

Northwind often needs less than a global order. Product-version processing can follow a per-product contract, while unrelated products proceed independently. A global sequence introduces coordination and throughput consequences that should be justified by a real cross-product requirement.

Hypothetical failure scenario. A redelivered search update receives a fresh UUID and is treated as a new operation. The target no longer recognizes its prior completion. A timestamp sort then lets an older source snapshot overwrite a newer one because the retry happened later.

Use operation identities to connect retries and reconciliation. Use attempt identities to explain execution. Use clocks under stated observation assumptions, and select causal or total ordering only where the application requires it. A single attractive identifier should not silently serve all these roles.

Layer 3 · Internals

Trade-offs and limits

ApproachProvidesRequires
Physical timestampUseful for human time and bounded real-world measurements.Clock error and rollback prevent it from proving arbitrary causal order.
Logical or causal clockCarries ordering information derived from communication.Its meaning differs from wall-clock time and may not yield one total order.

Recovery decision

Hypothetical scenario: A wall clock moves backwards and a last-write-wins policy discards a later user edit. Choose version/causal semantics that match the domain and handle clock rollback explicitly.

No. Identifier structure or physical time can be useful, but causal dependence needs evidence of observation/message relationships, and concurrent events may have no causal order.

Write your design before revealing the review

Can sorting UUIDs or wall timestamps recover the exact causal history?

Evidence you can explain in your own design

Drafts and self-review are stored only in this browser. They are separate from reading completion.

Compare your decision

No. Identifier structure or physical time can be useful, but causal dependence needs evidence of observation/message relationships, and concurrent events may have no causal order.

A wall clock moves backwards and a last-write-wins policy discards a later user edit. Choose version/causal semantics that match the domain and handle clock rollback explicitly.

Check your understanding

Can sorting UUIDs or wall timestamps recover the exact causal history?

No. Identifier structure or physical time can be useful, but causal dependence needs evidence of observation/message relationships, and concurrent events may have no causal order.

How would you recover from this failure: A wall clock moves backwards and a last-write-wins policy discards a later user edit. Choose version/causal semantics that match the domain and handle clock rollback explicitly.

Start with the exact boundary that failed. Attach identity and the relevant ordering metadata. Advance logical clocks according to observed causality. Choose a sequencer only for operations that need a shared total order. Then recover evidence through the observation path: Compare revisions using the declared rule. Treat concurrent updates as concurrent rather than inventing causality. Retain enough metadata to resolve or surface conflict. Preserve the distinction between a confirmed state change and an unavailable response.

Which assumption in the worked calculation would a burst or concentrated tenant invalidate first?

Hypothetical clocks can each differ from reference time by ±5 ms. Two observed timestamps 6 ms apart do not prove real order, because the uncertainty intervals can overlap. A scalar logical clock orders causal predecessors before successors, but the reverse inference is invalid: a smaller scalar timestamp need not mean a causal predecessor. Recompute the affected resource rather than multiplying unrelated storage and network budgets by the same factor. Distinguish physical timestamps, causal order and an agreed total order. Clock synchronization has error bounds and failures. A timestamp alone does not prove that an observed event happened before another across machines.

Which component in this topology could be removed from a smaller first deployment?

Event origin, Logical clock, Partition log, Causal reader name responsibilities, not a requirement for separate processes. Co-locate responsibilities when their transaction, trust and capacity boundaries permit it. Attach identity and the relevant ordering metadata.

What evidence must a caller have before relying on the observation path?

Compare revisions using the declared rule. Treat concurrent updates as concurrent rather than inventing causality. Retain enough metadata to resolve or surface conflict. No. Identifier structure or physical time can be useful, but causal dependence needs evidence of observation/message relationships, and concurrent events may have no causal order.

45-minute interview rubric

  1. 00–05: scope event and causal information.
  2. 05–12: identify the limiting resource and derive the domain workload above, retaining units and assumptions.
  3. 12–28: draw causal information, numbered writes and reads.
  4. 28–40: challenge recovery: Choose elapsed time, causal order or total order explicitly.
  5. 40–45: defend event_id placement, observations and remaining assumptions.

Go deeper

Decision log

Choose elapsed time, causal order or total order explicitly.

Preserve event identity and causal information ownership.

Revisit changed workload, observations or recovery objectives.