Loading
0x20Lesson 3 of 9

Reason about time and ordering

Distinguish wall-clock timestamps from causal order.

14 min 5-question quiz
By the end of this lesson you can
  • Explain clock skew, logical ordering, and why timestamps alone do not prove causality.

Machines keep separate clocks, and those clocks drift or jump. Two events with close wall-clock timestamps may not have a reliable order. Lamport clocks provide a logical ordering rule: increment a local counter for each event, and when receiving a message set the counter to one more than the maximum of the local value and the received value. This preserves causal order, but does not measure elapsed time.

A Lamport timestamp can say that one event is ordered before another in the logical clock scheme. If you need to know whether two events are concurrent, a vector clock carries more information. Neither clock replaces synchronized time for deadlines.

Practice: run a Lamport clock by hand

Two rules cover everything:

  • Local event or send: add 1 to your clock.
  • Receive: take the larger of your clock and the message’s timestamp, then add 1.

Try it

Up to 15 XP

Work out each timestamp

All clocks start at 0. Work out each new value before it’s revealed.

At the end, compare the last events on A and C. Their numbers can look ordered even when neither event could have affected the other.

ABC
  1. local event?

Practice: spot the skew

Try it

Up to 15 XP

Read merged logs from two machines

These logs come from two servers, merged by timestamp. Something is impossible.

Round 1 of 1: An effect before its causeScore 0/0

Which line can’t really have happened at the time it shows?

Merged logs, sorted by wall-clock time

Key takeaways

  • Physical clocks can disagree.

  • Logical clocks track ordering, not elapsed duration.

  • Use monotonic time for local deadlines and timeouts.

Lesson quiz

5 questions · pass with 4 correct · up to 50 XP

Passing this quiz completes the lesson and keeps your streak going. Questions you miss come back in review sessions later.

Questions about this lesson

Stuck? Ask. Figured something out? Share it. Explaining is one of the best ways to learn.

Loading posts…