Ahmet
Ahmet

Reputation: 11

Generate unique short ids on multiple servers

I was using shortid package to generate unique room ids, it works fine when using with only one server but i don't think ids will be unique if you use it on more than one server. Is there a way to generate unique ids on multiple servers without duplicates?

Upvotes: 0

Views: 416

Answers (2)

Rahul Rana
Rahul Rana

Reputation: 455

lets say you have server id's 1,2,3 . so just add server id to the number generated it ensure unique as you know in one server it will surely be unique.

Upvotes: 0

Quentin
Quentin

Reputation: 943510

Is there a way to generate unique ids on multiple servers without duplicates?

From the documentation you link to:

If you are running multiple server processes then you should make sure every one has a unique worker id. Should be an integer between 0 and 16. If you do not do this there is very little chance of two servers generating the same id, but it is theoretically possible if both are generated in the exact same second and are generating the same number of ids that second and a half-dozen random numbers are all exactly the same.

Upvotes: 3

Related Questions