💾 Archived View for tilde.pink › ~kaction › log › 2024-04-03.1.gmi captured on 2024-06-20 at 11:51:30. Gemini links have been rewritten to link to archived content

View Raw

More Information

-=-=-=-=-=-=-

Universal Unique Identifies are good, use them

There is a thing called Universal Unique Identifier (UUID). It is a way to randomly generate 128 bit number that it won't coincide¹ with any other number generated using the same algorithm; no coordination authority needed.

It sounds like a magic, but it works. Actually, git does something similar: independently made commits never¹ collide.

Unlike more convention idea of enumerating things with integers, UUID's have multiple advantages:

1. They can be assigned by client. This allows greater level of parallelization.

For example, if GitHub pull requests were using UUID's, API call to make a pull request and API call to make an issue mentioning that pull request could have been done in parallel. Since pull requests are numbers, the only way to get pull request number is to wait for the API call creating it.

2. When some object is imported from one system to another, UUID's can be imported as-is, while numbers require keeping track of the mapping between different numeric identifiers in different systems.

3. Random UUID's (UUIDv4) do not reveal information about object count and rate of growth. Probably doesn't matter for issues in a bug tracker, can be significant for users or orders in a online shop.

4. Humans never try to type UUID's, they copy-paste them. For numbers, humans tend to believe that they can type numbers. They can't, not without typos.

5. You can't run out of UUID's. You can't run out of int64 too, but you can easily run out of int32.

There are some downsides, sure, but they are minor:

1. UUID's are bigger, which means somewhat bigger database index size and slightly slower comparison. Usually, difference is neglectable.

2. Some humans are scared by long 36-character strings.

And yet, despite all these wonderful properties, again and again, server applications choose to use integers for pretty much everything. Debbugs, GitHub, GitLab, Gitea, Jira, ICQ (who remembers?), QuickBase (who knows?).

Even SourceHut, daring to defy "modern web" design patterns, still chose to identify issues on the bug tracker with integers. Sad.

Migrating existing system is usually way too painful and not worth it, but if you are creating something from scratch, please consider using UUID's and allowing client to pick them. Thank you for allowing me to stay offline for a bit longer.