dylang / shortid

Short id generator. Url-friendly. Non-predictable. Cluster-compatible.
https://www.npmjs.org/package/shortid
Other
5.74k stars 258 forks source link

How does shortid ensure uniqueness across restarts? #95

Open Ne0nx3r0 opened 7 years ago

Ne0nx3r0 commented 7 years ago

I noted this line "Apps can be restarted any number of times without any chance of repeating an id."

I can't seem to sort out how this is accomplished. How does shortid ensure uniqueness with the same settings across restarts?

irfaan commented 7 years ago

https://github.com/dylang/shortid/issues/58#issuecomment-166401161

ai commented 6 years ago

There is no insurance in any random ID generator. The same problem in UUID 4.

Just use bigger ID size, to reduce the probability of collision. I recommend to check Nano ID since it has lower collision probability.