Ordering
There is no global 'now' in a distributed system. Order exists only where something assigns it, so decide which order you need and who assigns it.
Concurrency
Learn it
Two users edit the same paragraph; two webhooks for one payment arrive; two servers log events. Which happened first? Wall clocks on different machines disagree by milliseconds or more, messages are delayed and retried, and "arrived first" isn't "happened first".
Order only exists where something assigns it.
Ways order gets established:
- A single sequencer: one process, one database row or one log partition assigns increasing numbers. Everything it sequences has a total order. The cost: all writes for that sequence go through one place.
- Per-key order: usually you only need order within an entity. Partition by that key and sequence each partition: parallel across keys, ordered within each.
- Causal order: "B was written by someone who'd seen A". Version vectors or Lamport timestamps capture it without a sequencer, but leave truly concurrent events unordered, needing a Conflict resolution and convergence rule.
Check
Why not order events from different servers by their wall-clock timestamps?Over a single TCP or WebSocket connection, messages arrive in the order sent. Across connections, reconnects, retries or multiple senders, nothing is ordered unless you order it.
Quick reference
The same ideas, condensed for revision.
How it goes wrong
- Ordering by client timestamps
- A device with a wrong clock reorders history or always wins.
- Two sequencers
- During failover both assign sequence numbers, and history forks.
- Assuming retries preserve order
- A retried message lands after a later one.
Instead, consider
- Commutative operations
- Results do not depend on order, so no ordering is needed at all (counters, sets, CRDTs).
- Hybrid logical clocks
- You need timestamps that respect causality and stay close to wall time across nodes.
In practice
- Database sequences / identity columns
- Total order per sequence, gaps possible.
- Log partitions (Kafka, Kinesis)
- Total order within a partition, keyed by entity.
- Per-entity version counters
- Increment with a conditional update to order changes to one row.
- Lamport clocks, version vectors
- Causal order without a central authority.
It assumes
- You know which order the application actually needs (total, per-key, or causal).
- The sequencer is unique, and its uniqueness is enforced during failover (fencing, unique constraints on position).
Explain it in your own words
Where you practise it
Further reading
Engineers describing it in systems they run.
- Uber's Real-Time Push Platform
Uber · Madan Thangavelu and others · Post, Dec 2020
Why polling was replaced, and the delivery problems push brought with it: resuming after a dropped connection, and knowing what actually arrived.
- How Figma's multiplayer technology works
Figma · Evan Wallace · Post, Oct 2019
Why a central server per document let Figma avoid most of the machinery of operational transforms, and how ordering works when anyone can insert anywhere.
Related concepts
- Append-only logs
Recording changes as an ordered, immutable sequence of facts, from which current state, history and replicas can be derived.
- Partitioning
Splitting data or work by key so each part is handled independently: scaling out, and giving each key a single owner.
- Conflict resolution and convergence
When replicas accept concurrent changes, a deterministic rule must merge them so every replica ends in the same state without losing intent.
- Leases and fencing tokens
Ownership that expires unless renewed, plus a token that lets the rest of the system reject an owner that has lost its claim without knowing it.
- Message queues
A durable buffer between producers and consumers that hands each message to one consumer at a time and redelivers it unless acknowledged.
- Publish/subscribe
Decoupling senders from receivers by topic: a publisher sends once and every current subscriber receives a copy.
- Generating unique identifiers
Making ids that are unique across machines and time, and choosing what else they reveal: order, volume, guessability, length.