Java – UUID randomly generated with duplicate
I use the following functions to generate UUIDs
UUID.randomUUID().toString()
In prod, we have 50 servers (application servers – each is a JVM), and as a first step, we generate a UUID that basically uniquely identifies the transaction
What we observe is that in server 6 and server 11, the generated UUID matches at least 10 to 15 messages per day, which is strange, because given the load, that is, about 1 million txns per day, it is strange that this UUID repeats on the same day
This is what we have done so far: 1) verify the application log - nothing is found there, and all logs are normal. 2) try to replicate this problem in the test environment, with a load similar to that of 50 servers in production - but this does not happen in the test environment. 3) check the application logic - this does not seem to be a problem, Because all 48 servers except 6 and 11 have copies of the same code base, they are generating a unique UUID per TxN
So far, we have not been able to track this problem. My question is basically whether there are missing JVM level or UUID parameters. Do we need to set a problem for this problem?
Please advise
Thank you, deepesh
Solution
If you have time, I'm sure you'll find the culprit During this period, I think it is worth promoting to answer:
You are generating pseudo-random UUIDs at multiple locations If you find no other errors, consider generating all pseudo-random UUIDs in one place, or generating real random UUIDs
So create a UUID server This is just a process of losing UUID blocks Each block may contain 10000 (or any appropriate) UUIDs This process verifies that each block does not contain duplicates after it is written to disk
The process of creating another distribution UUID block Maybe it's just a web service that returns an unused block when getting a request The transaction server requests a block and then consumes these UUIDs when creating a transaction When the server uses most of the allocated UUIDs, it requests another block