dylang / shortid

Short id generator. Url-friendly. Non-predictable. Cluster-compatible.

Home Page:https://www.npmjs.org/package/shortid

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Collision/ Duplicate Ids getting Generated In our Production with this module

pssvenkatrao opened this issue · comments

I am using the default setting
shortid.characters("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_");
shortid.generate().substring(0, 5);
I am seeing the duplicate IDs generating and resulting in failure when I have short id as unique index while saving in DB.

We are running the code in 5 PODs in each of kubernetes clusters.. Please suggest.

  1. shortid is deprecated. Use Nano ID.
  2. 5 symbols are not enough to prevent collisions in complex systems.
  3. Here is ID length and collisions calculator to choose the best length for you.