Comment by dtjohnnymonkey
6 hours ago
It would be hard to know whether there is a collision at generation time. If you did know, it implies a lookup in a global database, then you are back where you started.
6 hours ago
It would be hard to know whether there is a collision at generation time. If you did know, it implies a lookup in a global database, then you are back where you started.
there's some ways around this. for example, if you generate and the db answers this uuid already exists, this obviously is a failure. will it ever happen in your lifetime? if it does, you can be almost 100% sure that there is a problem in your random number generator. but those DO exist, like the CA certs that had to be revoked recently because they had like the number 4 as a random key
now, what to do with such an error? I think you should either log the error and retry with another uuid, or pass the error back to whoever called you (often the user, giving them an error page). Or maybe you will try for N times, and then return an error. what you can't do is to pretend everything is fine
if you do retry then it's just generating the uuid again with extra steps. i think this is fine
that's a new failure mode for sure, but not very different from other failures like connection loss to the db (also a fatal error, which in this case always should be surfaced to the caller). every networking API should have some possibility for error, and in this case this is just a new kind of error