Live data from Hacker News

Goodbye integers, hello UUIDv7

buildkite.com

371–376 of 376 posts

Re: Goodbye integers, hello UUIDv7

#371
post #342

Earlier quoted context omitted.

> It seems like the only real use case for these timestamps is to get data from around the same time together. Yep. > A second is fine for that. Not when you're doing O(1k-1M) operations per second, it isn't!

I’d think that the locality would only matter at the scale of your query. I’m sure someone has queries with a window less than a second and so much traffic, but it seems niche enough to not optimize the standard for it. I could definitely be off. I work at a company that gets those levels of traffic but don’t deal with it directly.

For me the whole value prop for ULIDs is that they can be generated by any node in a distributed system without coordination, while roughly preserving time order. "Roughly" meaning: all IDs will be globally ordered at millisecond precision, subject to the accuracy of each node's system clock; and IDs from a specific node will be locally ordered, subject to the details of the monotonicity part of the ID generator. This is important for me, because most of the things I attach IDs to will happen many many many times per second.

Re: Goodbye integers, hello UUIDv7

#372
post #347

Earlier quoted context omitted.

They’re not even strongly sequential (is there a term for this?). The gaps between them can be arbitrarily large.

They are sequential, where they are in a sequence where one is clearly before or after another. They're not monotonic.

Thanks! This is what I was looking for.

Re: Goodbye integers, hello UUIDv7

#373
post #364
post #332

Earlier quoted context omitted.

Sure you can, just prefix the encrypted identifier with a version number. https://app.example.org/file/1:abcdef12345 -> decrypt abcdef12345 with key "1" to yield UUIDv7 key of file (no matter what the latest key is)

An incrementing version number would once again leak time information. Even a not incrementing version number would leak that kind of information, because if you know the timestamp of another ID with the same version. I think there is no good alternative to random external identifiers.

Oh that's a good point.

Re: Goodbye integers, hello UUIDv7

#374

Earlier quoted context omitted.

Unless you have specific needs, the only type of UUID you should care about is v4. v1: mac address + time + random v4: completely random v5: input + seed (consistent, derived from input) v7: time + random (distributed sortable ids)

It would seem sequential keys for database performance is more than a 'specific' need.

Those are not helpful for database performance in a general sense. Last product I worked on used v4 uuids as primary keys without any issues - single master database, sorting by creation time only used in admin panels. You can index on created_at if needed. The IDs being sortable would be a non-feature.

Generating sortable IDs in very high volume, in a distributed architecture, is a problem very specific to systems like social networks, metrics collection etc. You won’t need that for your average e-commerce app or machine parts database.

Re: Goodbye integers, hello UUIDv7

#375
post #64

Earlier quoted context omitted.

UUIDs are 128 bits, or 16 bytes. They have infinitely many possible string representations. Those strings are not the value, they're a transformation of the value.

The strings are how HUMANS not machines interact with the UUID. When your java stacktrace spits out a log with an UUID it's going to spit out a STRING because it's written for you and not the computer. When you take that UUID and go start sniffing around internal systems you're going to copy the UTF-8 string representation.

OK, but you don't store the string representation in your DB, or on disk, etc.

Re: Goodbye integers, hello UUIDv7

#376
post #166

As a beginner I treated and understood (SQL) databases as something I have to use in order to store stuff. Later I was excited about the power and expressiveness of SQL and its extensions. There is a ton of leverage and you can make it so that interfacing with it directly becomes much more useful. However now I’m in a different phase. I see it as a durable data structure. I think in terms of “what does it provide to…

As a beginner I thought of the database as a backend for the app. Now I think of the app as a frontend for the database. :-D

Crud, you're right!
Post reply on HN