Skip to content

Checking and generating Stelace server keys or identifiers using random characters

License

Notifications You must be signed in to change notification settings

stelace/stelace-util-keys

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

98 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

Checking and generating Stelace server keys or identifiers using random characters

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •