4 ms·
They're for distributed systems. The entire point is that different computers can generate ID's that can be merged in a database later on and not collide. And
by crazygringo 4y ago
They're for distributed systems.
The entire point is that different computers can generate ID's that can be merged in a database later on and not collide.
And the way they're designed is less likely to collide than random numbers are. (But you need to pick the appropriate UUID version to ensure that, depending on your system's architecture.)
If you're generating ID's that originate in a single centralized table, you don't need UUID's -- autoincrement or random integer is the simpler choice.
- vanviegen 4y agoYou don't need a UUID for that. A 128 bit random integer will work just fine. Better even, as no bits are wasted on meta data.
- vanviegen 4y agoI'm getting down votes, presumably because people think what I said is incorrect. Would anybody care to explain how UUIDs can have lower probability of collision than just random bits? (Apart from using a central coordinator for handing them out of course, which would defate the whole point.)
- JoeAltmaier 4y agoA UUID is random bits. The statement was oxymoron
- edflsafoiewq 4y agoBut it isn't. A UUID is a disjoint-union of several different types of IDs, only one of which is just random bits, and if random bits is all you care about, then "random 128-bit number" is not only clearer but gives more entropy than "version 4 UUID". That what I'm trying to ask, what is the purpose of this disjoint union, when would you ever use the "UUID-ness" of UUIDs (which is not the same as asking about the virtues of UUIDs of a particular version).
- JoeAltmaier 4y agoThe virtue is, software has some idea what a UUID is. There's a mostly-random version which is also understood. If you want to start doing your own thing, a random number is good. It's hard to get a good random number. I suggest starting with, hey you guessed it, the UUID library.
- BeefWellington 4y agoIt's because this statement: You don't need a UUID for that. A 128 bit random integer will work just fine. Basically reads: You don't need a UUID for that. A UUID will work just fine.
- vanviegen 4y agoThe rfc is rather long for a UUID being just a random integer... But if we're talking about UUID v4, it seems that 122 out of 128 are indeed random. [1] So why not just go all the way? Who cares about these 6 bits of meta data? [1] https://www.rfc-editor.org/rfc/rfc412 https://www.rfc-editor.org/rfc/rfc412
- crazygringo 4y agoYou can easily look it up on Wikipedia. [1] But version 1 of UUID's, for example, concatenates a MAC address, a timestamp, and a "uniquifying" clock sequence. As long as you're ensuring your MAC addresses are all unique (which they should be, except for manufacturing error) and only one UUID library per device, collisions are impossible. Whereas with random numbers, there's always a chance of collisions. (There are also other versions of UUID's that do include randomness, with collision potential, in exchange for not revealing information such as timestamps and MAC addresses.) [1] https://en.wikipedia.org/wiki/Universally_unique_identifier https://en.wikipedia.org/wiki/Universally_unique_identifier
- vanviegen 4y agoAh, got it. Reading the spec, that seems like an awful lot of trouble to prevent something that will never happen anyway. Just wondering, can v1 guarantee uniqueness with multiple processes using the same network adapter or within containers?
- edflsafoiewq 4y agoOkay, thanks. Thinking about it a little more I think I get it. 1. We want a single truly universal namespace. 2. We want to have different methods of generating IDs, since there are a lot of different people in the whole universe and they may have different needs. 3. Each single method is designed to not generate collisions. 4. But there could be collisions between different methods. So some bits are added to show what method was used to generate the ID to guarantee IDs generated by different methods don't collide. This is also why we need a spec that defines what each method is, the versions are like a scare global namespace that needs to be allocated carefully. I think the reason I found this difficult is most of the times I see UUIDs, (1) and (2) aren't actually needed (this article being representative).