Skip to content

Latest commit

 

History

History
15 lines (9 loc) · 1.54 KB

README.md

File metadata and controls

15 lines (9 loc) · 1.54 KB

CircleCI JavaScript Style Guide Conventional Commits

stelace-util-keys

Checking and generating Stelace server object IDs, keys or other identifiers using random characters and some tricks.

Some math about ID collision

Supposing we are able to generate 10 000 objects per second, of the same type, say asset (ast_ prefix), in the same platform and environment, the probability to have an ID collision during such a single second is roughly Math.pow(10000, 2)/(2 * Math.pow(62, 9)) = 4e-9 (Birthday problem), since we have 9 random chars available for ast IDs, including “shuffler” part (called G in JSDoc comment in generator.js).

In other words, supposing we’re able to constantly generate 10 000 objects per second in the same table, and using a geometrical law with the probability of collision we’ve just computed, we will statistically have a collision after 2.7e8 seconds, or more than 8 years of constant heavy load and 2500 billion objects generated (let’s imagine it’s a bulk upload…).

Quite an acceptable risk of generating a single 500 error.