News for hackers. Stuff that matters.
Re:Moving Away from UUIDs by hn_user2 on Monday November 21, 2022 @06:24PM (#33699631)
My only wish is that UUIDs were sortable and still contained their timestamp. When bug hunting, sometimes things become a little more obvious when there is an exact start and end to ids with issues.
Re:Moving Away from UUIDs by ilikehurdles on Monday November 21, 2022 @06:33PM (#33699718)
UUIDv7 is sortable by time but I’m not sure if it’s possible to derive the time stamp from the UUID somehow.
Re:Moving Away from UUIDs by jayknight on Monday November 21, 2022 @06:54PM (#33699903)
The first 48 bits of uuidv7 is the number of microseconds since the epoch.
Re:Moving Away from UUIDs by dexwiz on Monday November 21, 2022 @06:31PM (#33699706)
Depends on the version used. Some of them do encode time. But since people don’t like to leak information they use the random version (4).
Re:Moving Away from UUIDs by andreareina on Monday November 21, 2022 @10:00PM (#33701224)
They're little endian so not sortable
Re:Moving Away from UUIDs by sgtnoodle on Monday November 21, 2022 @10:30PM (#33701432)
What does that have to do with anything?
Re:Moving Away from UUIDs by andreareina on Monday November 21, 2022 @10:45PM (#33701555)
>>>> My only wish is that UUIDs were sortable and still contained their timestamp. When bug hunting, sometimes things become a little more obvious when there is an exact start and end to ids with issues.

>>> Depends on the version used. Some of them do encode time.

Encoding time isn't enough, it has to be big endian (unless you write a special sorting function for uuids). Timestamped uuids store the timestamp as [timestamp_low, timestamp_mid, version(!), timestamp_high][1] which doesn't sort right.

[1] https://en.m.wikipedia.org/wiki/Universally_unique_identifie...

Re:Moving Away from UUIDs by pmontra on Tuesday November 22, 2022 @02:14AM (#33702988)
According to that Wikipedia page the binary representation of UUID 1 is big endian. It's the date-time and MAC address version.
Re:Moving Away from UUIDs by andreareina on Tuesday November 22, 2022 @07:21AM (#33704980)
The whole 128-bit value is encoded in big endian. But the fields decompose into something that's not. If you search the page for "UUID record layout" you'll find the timestamp as I've described it.
Re:Moving Away from UUIDs by sgtnoodle on Wednesday November 23, 2022 @01:37PM (#33722923)
Last week I replaced an old broken window. I took a fragment of glass to the local glass company, and asked whether they cut custom glass. The receptionist said, "No, we do not." After some back-and-forth, I realized she thought I wanted to provide my own glass. I clarified, "I am just trying to replace a broken window." She handed me a form, and the next day I had a correctly shaped glass pane.

If UUIDs contain time information, then they can be sorted by time. The details of the encoding, while important for actually implementing the sorting algorithm correctly, don't really seem relevant when reasoning at a high level?

Re:Moving Away from UUIDs by myvoiceismypass on Monday November 21, 2022 @06:28PM (#33699673)
There are KSUIDs that aim to satisfy this

A go ref impl: https://github.com/segmentio/ksuid

Re:Moving Away from UUIDs by scrollaway on Monday November 21, 2022 @06:31PM (#33699705)
Re:Moving Away from UUIDs by vbezhenar on Monday November 21, 2022 @08:23PM (#33700618)
I implemented it myself. Was a little bit tricky, but not rocket science.
Re:Moving Away from UUIDs by Too on Tuesday November 22, 2022 @01:03AM (#33702571)
Mongodbs ObjectId has this property.
Re:Moving Away from UUIDs by kube-system on Tuesday November 22, 2022 @01:46AM (#33702840)
I’ve always liked the pattern of putting timestamps on any objects in my DBs.
Re:Moving Away from UUIDs by mirzap on Tuesday November 22, 2022 @05:58AM (#33704398)
You can use ULID and store it as UUID since they are the same size. You can check this article for the details:

https://blog.daveallie.com/ulid-primary-keys