Search code examples
uuid

Should I worry about UUID uniqueness


I am using this https://www.npmjs.com/package/uuidv4 module to identify uniqueness of the user. Should I worry that 2 people might get the same uuid? What if I store of all given uuids for the day and before I give new uuids I check if it already exists in the database? And then after a day I would empty my database and repeat the process. Is it a good approach? Am I missing anything?


Solution

  • Should I worry that 2 people might get the same uuid...

    No you shouldn't. UUID's are unique for practical purposes.

    From Wikipedia: UUID:

    ..., the number of random version 4 UUIDs which need to be generated in order to have a 50% probability of at least one collision is 2.71 quintillion...

    As for:

    What if I store of all given uuids for the day and before I give new uuids I check if it already exists in the database

    You should have a Unique Key constraint on your table. Even if you do get a collision the DB would reject it.