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

Using shortid on many clients. #114

Open hifall opened 6 years ago

hifall commented 6 years ago

We have an SaaS app where many (potentially thousands) of client SPA's (Single Page Application) issue requests to the server.

In order to filter duplicate requests: 1 each request hits the server with an ID; 2 each time a request comes in, the server checks the request's ID -- if processed, simply ignore; otherwise proceed as usual;

Is shortid good for this purpose? How likely 2 or more SPA instances generate the same ID using shortid?

Thanks!

yentsun commented 6 years ago

@hifall for request id generation you can try generators with random part as server instance id and predictable (increment) part as request number:

This way you are safe from request id collisions.

hifall commented 6 years ago

Thanks @yentsun, will check the links out shortly!

ai commented 6 years ago

Just use Nano ID. It is less predictable and has longer ID.