Hybrid clocks
How TeselaDB orders versions without a central clock.
TeselaDB orders document versions with hybrid logical clocks (HLC). It needs neither a central clock nor atomic clocks.
How it works
HLC timestamp = [ 8 bytes: physical milliseconds ][ 4 bytes: logical counter ]
node A ───●────────────●─────▶ (physical clock + counter)
\ ▲
message │ the receiver moves its timestamp forward if the one it got is larger
▼ │
node B ──────●────────●──────▶Each timestamp joins 8 bytes of milliseconds of the physical clock and 4 of a logical counter. Each node moves its timestamp forward with its clock, and when it receives a message with a larger timestamp, it adopts it. So, if one event causes another, the second always has a larger timestamp.
The clocks of two nodes can differ by up to 250 ms, because each stays within 125 ms of the median. A read that finds a version inside that window ahead of its timestamp does not know whether it happened before it, so it restarts at a later timestamp to see it.
What it means for your application
Reads never return a result that contradicts the real order of writes. In exchange, some restart and take a little longer.
Limits
A node whose clock drifts more than 125 ms from the median hands over its leaderships until it is back within the margin. Without NTP, that happens often.