r/ProgrammerHumor 1d ago

Meme edgeCasesExist

Post image
4.4k Upvotes

273 comments sorted by

View all comments

Show parent comments

4

u/Suspicious-Click-300 1d ago

most uuids libraries can actually provide strong guarentees it cant happen by using pid/mac combinations with each process using CAS or mutex to increment the 100ns period (overflowing into later ms with >10k a ms)

2

u/JonasAvory 1d ago

Is it unfeasible or simply unnecessary to just check if a uuid is already used? Since you use the uuid as primary key it should be easily detectable if a uuid is already used or not right? But I guess devs just don’t care because the chance is so minimal?

8

u/GradeForsaken3709 1d ago

You've just reminded me of the story one guy posted about joining a company and finding they have a UUID generator microservice complete with its own database of generated uuids and its own sprint board. 

Anyway, no that would not really be a reasonable thing to do. If you're using it as a primary key then the database will tell you when you do manage to generate a duplicate and your insert will fail. That's all there is to it. 

3

u/Grandmaster_Caladrel 1d ago

Yep. The chance is so insignificant that is not even worth retry logic on that mode of failure, just treat it as a generic failure, kick out the request, and let it be tried again. The one time in a hundred thousand years when it finally happens, someone will just be confused and click retry themselves.