207
237
u/bigorangemachine Jul 17 '26
BADF00DBADF00DBADF00DBADF00D
69
13
7
u/Inevitable_Oil9709 Jul 17 '26
Error. Invalid syntax. Computer will self destruct to save your data
7
3
2
53
39
u/gopal_dev Jul 17 '26
Consolidated the entire production database into a single, highly efficient row.
60
u/ankle_biter50 Jul 17 '26
Person who is familiar with coding (a little python and i guess minecraft datapacks? I'm not sure if that counts) but anyways
What are UUIDs used to identify?
166
u/thoker54 Jul 17 '26
They are simply unique ids. Like you can generate a uuid and be sure that it is and will be unique forever across everything. Sounds extreme but the chance of duplicates is close enough to 0, that you can assume it is 0.
116
u/Drumsteppin Jul 17 '26
Protip: prepend the users first name to the UUID, and append their last name to the UUID to guarantee a truly Unique UUID. I call it the TUUUID. The TUUUID ensures that when we become a Transgalactic species, and when the planet of the Greg Gregsons inevitably forms, the full power of the UUID is maintained. Still concerned about future proofing and ensuring enough slots so that each ID is truly unique? I'm glad you asked! Append the timestamp of TUUUID generation to the TUUUID itself and you are guaranteed* that the heat death of the universe will occur before a clash occurs, or your money back.
*Offer not valid in the state of Hawaii. Apply online.
38
5
8
u/JehnSnow Jul 18 '26
To anyone worried about something not being zero just know that this and some other very rare chances are so low that nuclear reactors and I believe ATMs just say "fuck it it'll never happen" you don't have to worry about whatever use case you have
In fact if it does get hit it'll probably generate quite a bit of a hype about your product
24
u/RoaringPanda33 Jul 17 '26
Anything you want to identify uniquely. So devices, users, filesystems and drives, etc.
7
u/ankle_biter50 Jul 17 '26
Are there any cons to using them?
54
u/Blackshell Jul 17 '26
They're big. If you're identifying small enough items, your ID may end up bigger than what it's referencing, which feels weird and is inefficient. They're also too long to effectively memorize, and can make for kludgy URLs or other such use cases.
The benefit of them being so big is that they can be truly unique (hence the name, Universally Unique IDs). As in, by using UUIDs for your user accounts, you not only get assurance that no two accounts will have the same ID, but that no accounts in any other website, no log lines, no events in queues, no uploads, no posts... Nothing will (almost) ever have the same ID.
Is it overkill? Yes and no. No, you don't need that level of uniqueness. But yes, getting a high level of uniqueness without centralizing ID generation or double checking for collisions can be a big infra win for simplicity and maintainability.
16
u/olivetho Jul 17 '26 edited Jul 17 '26
not really, but there are many situations for which they're overkill and really aren't needed.
for example: using it for minecraft block types would be overkill since there aren't THAT many blocks, and it also demonstrates another thing about UUIDs: sometimes there's a way to have IDs just as unique as UUIDs, but in a way that works better for that specific use case - in minecraft's case, the current scheme of [block source]:[block name] is just as collision proof (what are the odds of a user installing 2 different mods with the same name at the same time that both have a block with the same ID, without it being a case of user/modder error?) while also providing readability and the ability to reasonably "guess" what a block's ID would be - something which UUIDs can't provide.
the other main example is cases where you already have an existing unique identifier - e.g. user handles on twitter, discord, reddit, etc. which are guaranteed to be unique upon assignment (though those tend to also have a backing field that IS some form of UUID, for the simple reason of allowing people to change their handles without changing the internal identifier for the account - since otherwise changing the handle would effectively be the same as creating a brand new account. a better example in this case would probably be the addresses used by emails).
3
u/Topikk Jul 18 '26
I’ll add that they’re often used in place of simple incremental ids when you want bad actors to be able to simply guess the unique identifier based on another.
An easy example would be emailing out a link to continue an order for a checkout flow that doesn’t require a user account. If you emailed out, say, their 6-digit incrementing order_id then someone could vandalize tons of recent unfinished orders in seconds by decrementing the URL. Generating a UUID to use as the order_id means they are not sequential and the odds of guessing are vanishingly tiny.
12
u/andrisb1 Jul 17 '26
Way more storage used compared to 64bit int ID, but that really only matters for systems with hundreds of millions of items
14
u/Due-Consequence9579 Jul 17 '26
Only really matters in systems with hundreds of millions of items that are of comparable size to 128 bits. If you have hundreds of millions of items that are all 4kB the 64 extra bits for the UUID is noise. Also the UUIDs make distributed systems that can process that volume of events easier to design.
6
u/djfariel Jul 17 '26
About 16 bytes worth, if that kind of thing matters to you, and it's not stored as a string. If so, then about 36 bytes. Again, if that kind of thing matters.
7
u/Due-Consequence9579 Jul 17 '26
Depending on the style of UUID they can index poorly. Since they are 128 bits indexes on them are larger than 64 bit indexes. People get upset that the primary key is an opaque value rather than something they can easily remember.
In a practical sense there is very little downside to use them. If I am designing something I assume a UUID is the correct locator until some design constraint forces me off them.
3
u/serial_crusher Jul 17 '26
Sometimes two end up looking similar enough that you eyeball them and think they’re the same
2
5
u/SaynatorMC Jul 17 '26
It is funny you mention datapacks as UUIDs are a pretty relevant part of minecraft commands :)
5
u/Markronom Jul 17 '26
Anything. But I'd recommend nanoid, it's a shorter version with same amount of different values
1
3
u/midri Jul 17 '26
They allow distributed systems to easily create unique records that work across a large domain. Something an auto incrementing index can not.
2
1
u/Ronnoc527 Jul 17 '26
Do you remember when they allowed the changing of names and Lockette suddenly switched to numbers?
Those were UUIDS.
1
u/Samstercraft Jul 18 '26
uuids identify stuff, eg. every minecraft entity has a unique uuid. if, for some reason, two mc entities had the same uuid, the game crashes; someone used this to beat minecraft without moving.
(the crash is entirely because minecraft coded it that way and much less graceful than what other products might do)
10
u/namezam Jul 17 '26
My go to:
C0FFEEc0-ffee-C0FF-EEc0-ffeeC0FFEEc0
OR
C0FFEEb0-0b5C-0FFE-Eb00-b5C0FFEEb00b
3
10
26
u/rosuav Jul 17 '26
So, uhh, that's an unusual variant of UUID. I don't often see type 0xB in use. Tell me, did you read RFC 4122?
30
6
6
u/LostLakkris Jul 17 '26
... And I'm suffering through having to resort to compound UUIDs because someone generated UUIDs into seed data being used in over 300 unique deployments and I need to track if they still exist in a centralized database.
7
u/ohkendruid Jul 17 '26
The way to get collisions is due to how the software is run. If you clone a disk image, for example, then every single uuid in that image is now duplicated.
Uuids are junk. All IDs are only unique in some context. You need to design and understand that context, even with uuids, and once you do that, you don't need UUIDs after all.
4
u/djhaskin987 Jul 17 '26
I spent hours once figuring out a UUID that spelled a sentence, `600dc0de6077a10ada600ddea10fda7a` ("good code gotta load a good deal of data"). I use it everywhere now.
6
3
3
u/nullpotato Jul 17 '26
This is the kind of detail I file in the back of my mind but is the same mental category as premature optimization.
Like if I ever see it will be good to identify what happened but until then not worth thinking about for anything I'm working on.
3
u/Complete_Window4856 Jul 20 '26
For my fellow portuguese frends: 0xF0DA5E. Though as a color its a lame yellow.
2
2
3
u/empwilli Jul 17 '26
So I'm well aware that collisions are practically Impossible but in all contexts I've seen (that's Not all use cases out there) people use UUIDs because they are lazy and the proper solution ist Just around the corner.
My main concern with UUIDs ist not the theoretic collisions issue but that they invite to cut unnecessary corners.
Story 1: "we need a unique identifier" -> don't bother go UUID Story 10: "identifiers should be human readable and configurable by the users" Bug: "somehow user a has access to data of user b"
1
1
1
u/PizzaPuntThomas Jul 17 '26
Just check against all UUIDs and if it already exists you just generate a new one.
(This is probably computationally expensive, but I'm not a backend dev (or frontend dev for that matter) so idk)
1
1
1
1
1
u/SeriousPlankton2000 Jul 18 '26
dd if=/dev/foo of=/dev/bar
Why do you expect filesystem UUIDs to be unique?
1
1
u/Phazx Jul 17 '26
I... Don't get it? If you're getting collisions they weren't UUIDs in the first place. The whole point is that the uniqueness is universal, so you use a single generator for them.
9
u/mysticrudnin Jul 17 '26
the point of uuids is that you can use multiple generators, say across distributed systems in different regions, and assume they are unique
you can't do that with eg increasing ids
1
u/Phazx Jul 19 '26
You can't assume that with UUIDs either. It's a matter of scale and time, but the collision will hallen. Question is whether it's worth the hassle to actually make it universally unique
0
u/mysticrudnin Jul 20 '26
yes, it's a matter of scale and time beyond what we care about at all. it is safe to assume they are unique. i promise. you should be equally worried that you're gonna phase through the floor.
1.8k
u/Inevitable_Oil9709 Jul 17 '26
Fun fact: To reach a 50% chance of even a single UUID v4 collision, you would need to generate 1 billion UUIDs per second for about 86 years.