Lamport timestamps explained in plain terms start with a simple observation: machines in a distributed system cannot trust each other’s clocks. The central question is how to tell which of two events happened first when the clocks on the machines involved disagree by seconds or more, and the answer is to stop asking the clock and count the events instead.
A Lamport timestamp is a number that each machine keeps and updates as it works, a logical clock that ticks on every event and is passed along with every message. When two machines exchange messages, their counters synchronise just enough to produce a consistent ordering of everything that happened.
This article explains how Lamport timestamps work, what the ordering they give you actually means, and where they fall short.
Key takeaways
- A Lamport timestamp is a logical counter, not a reading from a physical clock.
- Each machine ticks its counter on every event and on every message received.
- Messages carry the sender’s counter, so the receiver can catch up.
- If one event caused another, its timestamp is always smaller.
- The reverse is not true: a smaller timestamp does not prove causation.
What a Lamport timestamp is
Leslie Lamport introduced logical clocks in a 1978 paper, and the idea has been a foundation of distributed systems ever since. Each process keeps a single number, starting at zero, and follows two rules: it increments the number before each local event, and when it receives a message, it sets its number to the maximum of its own number and the timestamp carried by the message, plus one.
Those two rules are the whole algorithm, and they are enough to guarantee the clock condition: if event A happened before event B, in the sense that A caused B or they happened on the same machine in that order, then the timestamp of A is smaller than the timestamp of B. The ordering respects causality, which is exactly what a distributed system needs.
It is worth pausing on what the numbers mean. A Lamport timestamp is not a time. Two events with timestamps 5 and 6 might have happened a second apart or a week apart, on machines whose real clocks differ wildly. The number only says that the event stamped 5 came before the one stamped 6 in causal order, or that the two events are unrelated and the numbers happen to fall that way.
How the clock ticks
Consider two machines, Alice and Bob, both starting at zero. Alice sends a message to Bob, incrementing her counter to 1 first and attaching that value to the message. Bob receives it, takes the maximum of his own counter, zero, and the message timestamp, one, and adds one, so his counter becomes 2. Any event Bob performs next will carry a timestamp of at least 3, which is safely after Alice’s send.
The rule matters most when a machine has been busy on its own. If Bob has already performed ten local events, his counter is at 10, and a message arriving with a timestamp of 3 does not drag him backwards. He takes the maximum, 10, adds one, and carries on at 11, which keeps his own history in order while still acknowledging the message.
Ties are broken with the process identifier. Two events on different machines can carry the same timestamp, because neither caused the other, so the system orders them by timestamp first and by process id second. The result is a total order, a single sequence that every machine agrees on, even though the underlying events were only partly ordered.
That total order is useful for deciding things like who gets a shared resource first. If two machines both ask for a lock, the one whose request carries the smaller timestamp, with ties broken by id, wins, and every machine that applies the same rule reaches the same answer without further discussion.
What the ordering guarantees, and what it does not
The guarantee is one-directional, and the direction matters. If A caused B, then the timestamp of A is smaller than that of B. But if the timestamp of A is smaller than that of B, A may or may not have caused B. The two events might be completely unrelated, on machines that never exchanged a message, and the numbers say nothing about that.
This is the fundamental limit of Lamport timestamps. They can tell you that two events are ordered, but they cannot tell you whether two events are concurrent, which is to say happening independently with no causal link. A system that needs to detect concurrency, for example to spot conflicting writes to the same key, needs a stronger tool.
That stronger tool is the vector clock, which keeps a counter per machine instead of a single number. Vector clocks can tell concurrent events apart from ordered ones, at the cost of more bookkeeping. Our guide to vector clocks explains the upgrade, and it is the natural next step after Lamport timestamps.

Lamport timestamps compared with other clocks
Logical clocks are one of three ways to put events in order, and the other two are physical clocks and vector clocks. Physical clocks are simple and familiar, but they drift and cannot be synchronised precisely enough to order events that happen milliseconds apart. Vector clocks are precise about causality but cost more to carry around.
The table below sets out the main contrasts.
| Aspect | Lamport timestamp | Physical clock | Vector clock |
|---|---|---|---|
| What it measures | Order of events | Wall-clock time | Causal history |
| Can detect concurrency | No | No, and unreliably ordered | Yes |
| Size per message | One number | One timestamp | One counter per process |
| Needs clock synchronisation | No | Yes, and it is never exact | No |
| Best for | Total ordering, simple cases | Human-facing times | Conflict detection |
The practical result is that Lamport timestamps suit systems that need a cheap, agreed order of events, while vector clocks suit systems that need to know which events were genuinely independent.
Where Lamport timestamps are used
Distributed mutual exclusion was the original application. Lamport’s own algorithm for granting a shared resource used timestamps to order requests, and every machine applied the same rule to the same ordered list, so no central lock server was needed.
Databases use logical timestamps to order transactions and to resolve write conflicts. When two writes to the same row arrive with different logical timestamps, the larger one wins, and every replica that applies the same rule converges on the same value, which is the last-writer-wins rule in its simplest form.
Event ordering in logs is another common use. When a system collects events from dozens of machines into a single log, Lamport timestamps give the log a sensible order even when the machines’ clocks disagree, which makes debugging a distributed failure far less confusing.
Modern systems often use a hybrid, a physical clock with a logical counter attached, which is sometimes called a hybrid logical clock. It gives human-readable times for display while keeping the causal ordering guarantees of Lamport’s design, and it is the approach used by databases such as CockroachDB. Our guide to linearizability explains the stronger consistency guarantee that such clocks are often built to support.
Strengths and limits
The greatest strength of Lamport timestamps is their simplicity. The algorithm is two rules, it needs one number per process, and it works without any clock synchronisation at all, which is why it has survived nearly fifty years of new hardware and new protocols.
They are also cheap. A single number rides along with each message, the update rule is a comparison and an increment, and no machine ever has to wait for a clock to catch up, so the overhead is essentially zero.
The limits are real, though. A Lamport timestamp cannot detect concurrency, cannot say how much real time passed between events, and can be misleading if a reader treats the number as a time rather than an ordering. Teams that need to know which writes genuinely conflicted, rather than just which came first in the total order, will outgrow Lamport timestamps quickly. Our guide to eventual consistency explains the setting in which that conflict question matters most.
Lamport timestamps checklist
- Use a logical clock when machine clocks cannot be trusted to agree.
- Increment before every local event, not just before sending messages.
- On receipt, take the maximum of the local and message counters, plus one.
- Break timestamp ties with the process identifier for a total order.
- Never treat a Lamport timestamp as a wall-clock time.
- Remember that a smaller timestamp does not prove causation.
- Upgrade to vector clocks when you must detect concurrent events.
- Consider a hybrid logical clock when humans need readable times too.
- Keep the counter durable if ordering must survive a restart.
Frequently asked questions
What is a Lamport timestamp in simple terms?
It is a counter that each machine increments on every event and shares with every message, so that events which caused each other always get increasing numbers.
Why can distributed systems not just use real clocks?
Because physical clocks drift apart and cannot be synchronised precisely enough to order events that happen close together on different machines.
What is the clock condition?
It is the guarantee that if event A happened before event B, then the timestamp of A is smaller than the timestamp of B, which Lamport’s two rules ensure.
Can two events have the same Lamport timestamp?
Yes, when they are concurrent, so systems break the tie with the process identifier to produce a single agreed order.
What is the difference between Lamport timestamps and vector clocks?
A Lamport timestamp is one number and cannot detect concurrency, while a vector clock keeps one counter per process and can tell concurrent events from ordered ones.
Are Lamport timestamps still used today?
Yes, directly in simple ordering tasks and as the logical half of hybrid logical clocks in modern distributed databases.
The bottom line
Lamport timestamps explained in one line are this: count the events, share the count, and order follows without any clock at all.
It is one of the smallest ideas in distributed systems, and also one of the most durable, because it replaces a problem nobody can solve, perfect clock synchronisation, with a problem anybody can.
This article is general information about how Lamport timestamps work, not advice about ordering events in a particular system.







