Clocks and ordering: logical and vector clocks
When two servers each record an event, which came first? Their clocks disagree, so timestamps can't always say (What goes wrong in distributed systems). Interviewers raise ordering whenever more than one copy accepts writes.
Letters between three cousins
Three cousins are planning a holiday by post. Their watches disagree, so the time on a letter can't show which came first. So they agree a trick: each letter carries a number, one higher than the highest number on any letter its writer has read. A reply always carries a higher number than the letter it answers. Later they improve it: each letter lists how many letters from each cousin the writer had read, like "Ana 3, Ben 2, Chen 0". Now if Ben and Chen both wrote "I've booked the flights" without seeing each other's letter, the lists show it: neither list is ahead of the other everywhere.
- the cousins → the servers, or replicas, that take writes
- the letters → the messages and writes passing between them
- the time on the letter → a wall-clock timestamp, unreliable across machines
- one number, higher than anything you've seen → a Lamport clock
- the list of letters read from each cousin → a vector clock
- neither list ahead everywhere → concurrent events: a conflict to resolve