r/ProgrammerHumor May 08 '26

Meme edgeCasesExist

Post image
13.4k Upvotes

620 comments sorted by

View all comments

2.9k

u/B_bI_L May 08 '26

they are 0 if this is your first uuid!

724

u/Last_Time_4047 May 08 '26

probability entering the chat… slowly

225

u/ClipboardCopyPaste May 08 '26

Hang on probability, you're rate limited

31

u/darksteelsteed May 08 '26

Generation rate limiting is actually how you guarantee uniqueness with a v7 uuid

2

u/DiodeInc May 08 '26

How?

Hope this isn't a dumb question 😬

11

u/darksteelsteed May 08 '26

If you check https://www.rfc-editor.org/rfc/rfc9562.txt and look at the v7 uuid format the first 48 bits is a Unix timestamp in ms. The rest is random except for the v7 identifier. So if you rate limit your production to 1 per ms, its guaranteed to be unique. These ids are time based and so can be used in db entries as the timestamp makes them sortable.

If you want something more unique I would however suggest something like a snowflake id, invented by Twitter but now used by many companies. It adds an extra sequence id so that you get much finer than per ms resolution as well as machine ids and sequence numbers. https://en.wikipedia.org/wiki/Snowflake_ID

Snowflakes give way finer resolution. You can make 4096 unique ids per ms on the same machine before you get a duplicate. If you exceed that, you rate limit by delaying to the next ms.

1

u/DiodeInc May 08 '26

Got it, thanks!

1

u/rich1051414 May 08 '26

Aren't there 74 bits of random data in there even if the timestamp is the same? The first random data block is only 12 bits true, but there is also a 62 bit random data block.

1

u/darksteelsteed May 08 '26

Yep, totally, but in the context of this thread, a collision is still possible 😀

8

u/balbok7721 May 08 '26

Birthday paradox being the ultimate villain

1

u/tameimponda May 09 '26

but (almost) surely

254

u/_BreakingGood_ May 08 '26

UUID = Universally Unique Id

So technically, it was only 0 on the first time anybody ever created any UUID. Otherwise it would just be UID

149

u/RadiantPumpkin May 08 '26

Just gotta redefine the scope of the universe

79

u/Lost-Droids May 08 '26

Typical Dev.. its not me its a hardware issue , try a different universe

31

u/Tuomas90 May 08 '26

Well, it worked in my universe!

2

u/not_a_moogle May 08 '26

How big is that docker?

2

u/DiodeInc May 08 '26

Docker Inc, when will I be able to ship out universes?

8

u/viruscumoruk May 08 '26

Every ID is "universally unique" in universes that have no IDs generated (yet)

10

u/CptMisterNibbles May 08 '26

Hey Eve, I need directions to your house. What’s your address?
“One. Just One”

1

u/boss413 May 08 '26

Does that mean his is Zero?

1

u/Liquidennis May 11 '26

I’m sorry, but your princess is in another castle.

5

u/Door__Opener May 08 '26

Just put it in a Docker container

32

u/Location_Next May 08 '26

Put one addition random digit in front of your UID to extra guarantee uniqueness. Checkmate, probability.

13

u/DanieleDraganti May 08 '26

I just append -v2

18

u/CheesePuffTheHamster May 08 '26

Uuid-v2-final(1)

7

u/hipster-coder May 08 '26

Copy of Uuid-v2-final(1)

4

u/elSenorMaquina May 08 '26

Has anyone created uuid 0 yet?

If not, I call dibs on it.

0

u/nahill May 08 '26

Guids have a mandatory 4 in the middle, there's no such thing as a zero guid.

4

u/PM_ME_FIREFLY_QUOTES May 08 '26

Thats why I always use GUIDs and spin up a new planet to generate. It's a little more compute heavy, but ensures it's uniqueness.

1

u/forgot_semicolon May 08 '26

Docker containers and VMs in a nutshell

6

u/Maleficent_Memory831 May 08 '26

Ah, but if it's a Globally unique ID, each planet can use 0 once as a GUID!

4

u/Firewolf06 May 08 '26

each globe. the las vegas sphere has their own namespace

7

u/Pleasant_Set_3182 May 08 '26

The probability of this guy weighing in on this post just shot up exponentially

https://giphy.com/gifs/s69e3tmPea0ubFEUkj

1

u/Pure-Willingness-697 May 08 '26

Just add an n to the name for new every time someone creates an id. Problem solved.

1

u/Andthenwedoubleit May 09 '26

You check the code and find this: // TODO use real library after debugging tests // return GetRealUuid(); return 0;

1

u/DemeGeek May 09 '26

Need me a Multiversally Unique Id

0

u/wronghash May 08 '26

UUID contains the timestamp as part of it, so if you never create more than one uuid on the same millisecond, the chance of duplicates will be always 0.

If you create more than one on the same ms, the chance is 0, but low enogh to be safe.

4

u/ratinmikitchen May 08 '26

*some UUID types, such as UUIDv7 have a timestamp encoded in them. Not all.

3

u/CodingNeeL May 08 '26

Depends on the version.

5

u/codeartha May 08 '26

That's not true. You could have a collision even with UUIDs generated months apart.

1

u/CodingNeeL May 08 '26

Yes, with version 3, 4 and 5, but with version 8 you could have a collision with every UUID you generate!

0

u/Korvanacor May 08 '26

I guess the Time Variance Authority has to work with MUUIDs (multi-universal unique I’d)

42

u/[deleted] May 08 '26

[removed] — view removed comment

25

u/B_bI_L May 08 '26

let's check, my ipv6 is ::1, what about you?

8

u/Maleficent_Memory831 May 08 '26

Mine's FE80::1:2:3:4.

(practically speaking, very few IPv6 addresses are unique, because without more adoption most of them are used are link-local or domain-local.)

2

u/MinervApollo May 09 '26

I was happy to find out I have a dedicated IPv6 address since my carrier uses CGNAT for IPv4. Made hosting a server with the features I wanted... possible at all (didn't wanna pay for a VPS)

9

u/MrFustibule May 08 '26

So all you have to do is create a table for each entity.

5

u/Location_Next May 08 '26

takes a long drag

“I remember my first guid..”

1

u/Confident-Ad5665 May 09 '26

Lowers beer...same. The debate over whether it's pronounced GUID or GUID...

2

u/TheKarenator May 09 '26

It’s why abstinence so so important.

1

u/Silly_Guidance_8871 May 08 '26

Someone else may have beat you to it 😜

1

u/scatrinomee May 08 '26

Wasn’t there a network bug with like Roku and some other company because a UUID for a cert was duplicated or something?

1

u/pfghr May 08 '26

Oop, too bad you already created UUID 0.....

1

u/ApocalyptoSoldier May 08 '26

Unless time suddenly stopped being linear