TheCandidStartup / TheCandidStartup.github.io

The Candid Startup Blog
https://www.thecandidstartup.org
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

2023/09/24/unique-ids #25

Open utterances-bot opened 9 months ago

utterances-bot commented 9 months ago

Unique Ids

They say that there are only two hard problems in Computer Science: cache invalidation and naming things. Cache invalidation is far too difficult, so let’s have a go at naming things. Specifically, how do you ensure that the name you use to identify some resource is unique?

https://www.thecandidstartup.org/2023/09/24/unique-ids.html

timwiegand commented 9 months ago

URNs vs ARNs

Patrick asked a great question over on LinkedIn.

Given your strong opinion on URNs, what do you think of AWS ARNs? They seem really useful when interacting with meta-services like IAM which need to refer to resources from multiple other services.

There are two reasons why I dislike URNs in general and Autodesk's use of them specifically. First, an URN is trying to be a totally universal meta-identifier. When, in a real system, would you need an indentifier for literally anything? That ambition means you need all the ceremony of registering with the IANA to add support for another type of id.

Autodesk tried to use URNs as the one and only identifier for resources in each service. You had to use an URN even when interacting with the service that owned the resource in question. All that extra context was no use to anyone. You were meant to treat URNs as opaque identifiers, so even if the context would have been useful, you were meant to ignore it.

ARNs avoid both problems. They aren't trying to be totally universal, only universal across AWS services. You only need to use them when the extra context is useful, when interacting with meta-services. The format is transparent and documented.

mpriestman commented 9 months ago

Just read this: https://buildkite.com/blog/goodbye-integers-hello-uuids Looks like ULIDs are going to become UUIDv7?

mpriestman commented 9 months ago

Also, UUID v6 and UUID v8! https://www.ietf.org/archive/id/draft-peabody-dispatch-new-uuid-format-01.html And Snowflake IDs? https://en.wikipedia.org/wiki/Snowflake_ID Just so many different Unique IDs out there to choose from!

timwiegand commented 8 months ago

Snowflakes and UUID v6-v8

Thanks for the links Michael! It's crazy how many different versions of ULIDs there are. There are three things I missed in the post that I'd like to call out now.

  1. Snowflake ids are the only 64 bit ULID variant I've seen. The trade off is that you need additional coordination to give each generator a unique machine id.
  2. The UUID v6-v8 proprosal feels very different from v1-v5. Rather than proposing an optimal representation, they've gone for a pick and mix approach which lets you encode any existing ULID in a UUID wrapper. Pick whatever timestamp precision, size of counter and size of random bits you like.
  3. I missed an important use case for ULID like ids. Databases that use B-trees as their storage representation are more efficient if new records are inserted roughly in order. ULIDs, Snowflakes and the new UUID versions all meet that requirement.