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

What happens after 100 years? #60

Closed benbro closed 2 years ago

benbro commented 2 years ago

Readme says that the timestamp provides over 100 years of life. What happens after 100 years? Does it wrap and use the same timestamp around 100 years ago? Will it break index logicality or other things? Moving 4 bits from the random part to the timestamp would make it 2000 years and wouldn't change much the library guarantees so I wonder why not do it?

steve-warren commented 2 years ago

The maximum value for the timestamp is 678305640950000000 ticks, which is 6/19/2150 11:21:35 PM.

This timestamp is encoded as

aWgEP

One second after, the timestamp will overflow to zeros:

00000

because the uint32 value overflows during this call:

binary.BigEndian.PutUint32(ksuid[:timestampLengthInBytes], ts)
achille-roussel commented 2 years ago

This is left for future generations to figure out... I in 50+ years we can think about changing the epoch or bit width for KSUID v2.

Depending on how you use the KSUIDs, the overflow may or may not be a problem, likely it will considering the assumptions applications tend to make. It will break the rough time-based ordering offered by KSUIDs.

If you are building applications that need to run for over 100 years, these concerns exist in many time-based systems (e.g. int64 nanosecond precision timestamps are only valid for 200 years or so I think). I'd love to hear about your use cases tho... who knows if Go will still be around in 2100+ :D

abraithwaite commented 2 years ago

I like thinking that in 100 years time when someone hits this on ancient software they'll take a screenshot of this report and share it with their team in their metaverse discussion room. :rofl: