Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I have "private" UUIDs

Tags:

uuid

Can I cleanly use a private UUID variant/version?

I use random UUIDs which I essentially consider to be big integers. Now I have the case where I would like to generate a "private" UUID which is not based on any one of the well known 5 variants/versions.

Should I "hijack" a well known variant/version I'll never ever use? Or should I use an unknown variant/version?

Neither the RFC nor wikipedia covers this topic.

like image 970
Vincenzo Z Avatar asked Oct 12 '25 05:10

Vincenzo Z


1 Answers

Nobody answered so I'll offer my considerations.

We use random UUIDs to identify objects within clear system boundaries. Although UUIDs are represented by 128 bits, there can only be 2 ^ 121 random UUIDs because the version (4 bits) and the variant (3 bits) are constants. (Actually variant 4 allows to use one additional bit and for the pedantic this could be added to the 121.)

I know we will never use versions 1, 2, 3 and 5. Unfortunately there are no provisions mentioned for the remaining 11 (16 - 5) version numbers in the RFC.

What I resolved to is to claim UUIDs of version 1 and variant 0100 as private (or local) ones. I reserved 4 bits for my own sub-type which leaves me an ample 117 bits per sub-type for my own use. For a few subsystems with deterministic IDs I can now create UUIDs that fit in the structures I use.

I am fully aware that these IDs might theoretically clash with externally generated UUIDs. But as the system boundaries are clear and external IDs are considered separately, this approach suits us and is practicable.

like image 125
Vincenzo Z Avatar answered Oct 16 '25 11:10

Vincenzo Z



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!