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 ?

  • If you trust your pRNG enough to generate random UUIDs, why not just use the same pRNG to generate long random integers? Commented Feb 8, 2021 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
    Commented Feb 8, 2021 at 14:14
  • Did you know you can tell a DB autoincrement to use a step higher than 1? You can set the step increase to 2 (or 3, 4 or however many nodes you have) and have US DB create even IDs only and EU DB create odd IDs only. It's like reserving a few bits out of the ID for a suffix.
    – Rad80
    Commented Jan 16 at 13:46

1 Answer 1


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.

  • What do you mean exactly by "client" Commented Feb 8, 2021 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. Commented Feb 8, 2021 at 18:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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