Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generating unique orderId and customerId does not guarantee 100% uniqueness, but it is possible to overlook the problem given the low probability #50

Open
Fernando-Granato opened this issue Nov 6, 2023 · 0 comments

Comments

@Fernando-Granato
Copy link
Contributor

For the generation of the unique orderId and customerId for NPG I thought to proceed from the timestamp in milliseconds by concatenating random way N characters between URI safe alphanumeric values.

I ruled out concurrency problems in generating the two ids in the same millisecond through a probability calculation described as follows.

Consider the length of the timestamp string in milliseconds = 13
So the random string to be generated will be 18 (maximum length of the unique id) - 13 = 5 characters
Suppose we have 2000 RPS on the service (very large number of requests) so 2 requests per millisecond.
The number of alphanumeric characters used to generate the random string is 65.

const val ALPHANUMERICS: String =
           "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-._"
     

We calculate all possible combinations $65^5 = 1 160 290 625$.

At this point $1 / 1 160 290 625 = 0.000000000861853$ (negligible probability of collision).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant