0

We have been relying on our database to generate IDs for our entities and guarantee uniqueness.

Recently, and because of GDPR, we are obliged to redeploy the whole system (EC2s, DBs, microservices, etc.. ) in Europe for EU clients, opening the possibility to id collision.

Team members have suggested the following so far:

  1. Making sure the second DB autoincrement has a sufficient offset (really not a fan)
  2. Using a centralized microservice backed with a DB to generate Ids (Introducing a very critical bottleneck)
  3. Using UUID v4 (seems to be the most reasonable approach so far)

It would make our lives significantly easier if they new generated IDs are purely numeric and not alphanumeric.

For now, we are considering option 3 (UUIDs) but with reinterpreting the bytes to be a numerical value.

Is this a safe approach ?
Are there any patterns or best practices for generating IDs of entities in the application layer ?

2
  • If you trust your pRNG enough to generate random UUIDs, why not just use the same pRNG to generate long random integers? Feb 8 at 13:00
  • UUIDs are usually not related to a random number generator with a public interface. I do have access to a UUiD generator but not to a 128 but random number generator. And UUIDs are standard.
    – gnasher729
    Feb 8 at 14:14
2

UUIDs are 128 bit integers, encoded in a string. If you can support 128 integers, you’re fine. Otherwise, take UUIDs as a 36 letter ASCII string. If you have 64 bit integers but not 128 bit, you can also store a UUID as two 64 bit integers.

If each client has a good UUID generator, you’re fine. If there are collisions, they are much more likely to come from a bug in your code than from a real collision.

And I’m just curious why a number would be easier for you than a string.

2
  • What do you mean exactly by "client" Feb 8 at 14:17
  • It is a very silly reason, but a number would be easier because all our entities have an id with a numeric data type. It is not big enough to hold a 128 bit anyway. Feb 8 at 18:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.