segmentio / ksuid

K-Sortable Globally Unique IDs
https://segment.com/blog/a-brief-history-of-the-uuid/
MIT License
4.9k stars 173 forks source link

KSUID is not nanosecond-aware #48

Closed loganintech closed 3 years ago

loganintech commented 3 years ago

The go source code shows that a wall time for time.Time is in fact 8 bytes, a uint64. Unlike how it's defined in this library to be 4 bytes, a uint32. This means we're throwing out the nanoseconds when generating the timestamps. Is there a particular reason for this? This breaks ordering for me where items are made within the same second.

achille-roussel commented 3 years ago

This is by design, KSUIDs are not meant to provide absolute ordering. Computer clocks cannot be synchronized accurately enough to provide these guarantee, so KSUID only offers rough ordering by their 4-byte prefix.

This property is often useful to narrow down the search space by performing prefix based matching, but if more precise ordering guarantees are needed the application needs to build this into its logic.