Skip to main content

Lamport Timestamps

Lamport timestamps are logical counters used in distributed systems to preserve cause-before-effect ordering without trusting wall clocks. The counter is monotonic: it only increases. Unlike one central sequence-number generator, Lamport timestamps work in leaderless and multi-leader designs. They preserve causality, meaning an event that caused another receives a lower timestamp.

Algorithm​

Each server has a node identifier and a counter. Two servers can have the same counter, but the node identifier breaks ties. When a server receives a message, it raises its counter above the received value before creating its next event.

Careful​

Lamport Timestamp implementations/use-case can be easily mistaken by Version Vectors - which have different purposes. Version Vectors are meant to decide wether two operations are concurrent or if it has any sort of causality dependency. Lamport Timestamps enforce the ordering of events.

Notes​

It might not seem so interesting at first but on asynchronous environments - like Messaging Systems - having some sort of causality to depend on can really help out. Some queues may lag behind and cause weird behavior - Lamport Timestamps can help with that.

Share: