hlc: a hybrid physical/logical clock package for Go

167 views
Skip to first unread message

Jason E. Aten

unread,
Jan 24, 2026, 1:22:07 PMJan 24
to golang-nuts
I have open sourced my hybrid physical/logical clock package, here.


HLC are useful for solving various problems in distributed systems.

The concept of an HLC was invented in this 2014 paper, to combine and preserve the convenient features of both physical and logical clocks:

"Logical Physical Clocks and Consistent Snapshots in Globally Distributed Databases" by Sandeep Kulkarni, Murat Demirbas, Deepak Madeppa, Bharadwaj Avva, and Marcelo Leone.

https://cse.buffalo.edu/tech-reports/2014-04.pdf

See for instance their use in CockroachDB and MongoDB as alternatives to Spanner's TrueTime approach when atomic clocks are unavailable.

https://cse.buffalo.edu/~demirbas/publications/augmentedTime.pdf

https://github.com/AugmentedTimeProject/AugmentedTimeProject

https://muratbuffalo.blogspot.com/2025/01/use-of-time-in-distributed-databases.html

Enjoy,

Jason

Michael Oguidan

unread,
Jan 24, 2026, 3:42:03 PMJan 24
to golang-nuts
Thank you very much

roger peppe

unread,
Feb 26, 2026, 11:42:15 AM (6 days ago) Feb 26
to Jason E. Aten, golang-nuts
This looks potentially useful, thanks.
One thing I'd pick up from the README, which says:

> The Go standard library time package does not provide a user-accessible monotonic clock.

That might have been true at one point, but is no longer the case.
monotonic clock proposal.

In short, time.Time.Sub on timestamps derived from time.Now will give the monotonic time interval
between them, regardless of leap seconds and the like.

So:
    t0 := time.Now()
    t1 := time.Now()
    d := t1.Sub(t0)

will guarantee that d is non-negative (assuming the underlying system provides access to a monotonic clock).


--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/golang-nuts/7718c100-4382-4f87-992e-7a3839331042n%40googlegroups.com.

Jason E. Aten

unread,
Feb 26, 2026, 11:56:50 AM (6 days ago) Feb 26
to golang-nuts
Hi Rog,

Yes, I am aware of that feature, but that does not expose an actual monotonic
timestamp reading to the user, and so I stand by
my claim that the Go runtime does not expose a monotonic 
clock to the user (like the hlc package provides).

take the difference of two local timestamps, but does not give an absolute time reading
that would correspond to any actual "time of day".

So I still see hlc as valuable for that otherwise un-addressed use case.

- Jason

Reply all
Reply to author
Forward
0 new messages