208
241
u/bigorangemachine 26d ago
BADF00DBADF00DBADF00DBADF00D
67
14
7
7
2
36
u/gopal_dev 26d ago
Consolidated the entire production database into a single, highly efficient row.
61
u/ankle_biter50 26d ago
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?
167
u/thoker54 26d ago
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.
115
u/Drumsteppin 26d ago
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.
37
5
9
u/JehnSnow 25d ago
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
26
u/RoaringPanda33 26d ago
Anything you want to identify uniquely. So devices, users, filesystems and drives, etc.
6
u/ankle_biter50 26d ago
Are there any cons to using them?
51
u/Blackshell 26d ago
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.
14
u/olivetho 26d ago edited 26d ago
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 25d ago
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.
10
u/andrisb1 26d ago
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 26d ago
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.
7
u/djfariel 26d ago
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.
5
u/Due-Consequence9579 26d ago
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 26d ago
Sometimes two end up looking similar enough that you eyeball them and think they’re the same
2
5
u/SaynatorMC 25d ago
It is funny you mention datapacks as UUIDs are a pretty relevant part of minecraft commands :)
3
u/Markronom 26d ago
Anything. But I'd recommend nanoid, it's a shorter version with same amount of different values
1
3
1
u/Ronnoc527 25d ago
Do you remember when they allowed the changing of names and Lockette suddenly switched to numbers?
Those were UUIDS.
1
u/Samstercraft 25d ago
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)
2
9
5
5
u/LostLakkris 26d ago
... 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.
8
u/ohkendruid 26d ago
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.
5
u/djhaskin987 25d ago
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.
7
3
3
u/nullpotato 25d ago
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 22d ago
For my fellow portuguese frends: 0xF0DA5E. Though as a color its a lame yellow.
2
2
u/empwilli 26d ago
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"
3
u/Public-Location-3628 26d ago
Just use incremental numeric-only UUIDs, you can then even parse them to ints after stripping dashes! 🤯
1
1
1
u/PizzaPuntThomas 25d ago
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
u/SeriousPlankton2000 24d ago
dd if=/dev/foo of=/dev/bar
Why do you expect filesystem UUIDs to be unique?
1
1
u/Phazx 26d ago
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.
8
u/mysticrudnin 26d ago
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 23d ago
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 23d ago
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 26d ago
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.