Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specify id length #81

Closed
praxiq opened this issue Nov 10, 2016 · 2 comments
Closed

Specify id length #81

praxiq opened this issue Nov 10, 2016 · 2 comments

Comments

@praxiq
Copy link

praxiq commented Nov 10, 2016

The automatic scaling of id length based on generation rate is pretty cool, but it has some drawbacks.

  1. As one user pointed out, if ids are generated rapidly in clusters, it can create ids that are too long.
  2. If run for a long time at a low rate, it can create ids that are too short! Generating 1 id per second, the ids stay short (9 characters = 54 bits). After only a year (30 million ids) the odds of a collision increase to 2.5%. (And if 4 different servers each generate 1 id per second, it'll only take 3 months to get the same odds of a collision!)

When I know my own use case and how important it is to me to avoid a collision, I'd like to be able to skip the timing code and just specify the length myself.

It'd be nice if I could call generate(12), and get output of the specified length. (Or, generateFixed could be its own function, separating out the timing code completely for those who don't want it to be part of their project.)

@flesler
Copy link

flesler commented Nov 10, 2016

There's no chance of collision if there's a single server or you set a different worker id on each. If you have more than 16 servers, you can device a way to give each server a letter and append it to IDs and then the amount of servers you can have in the cluster safely skyrockets.

As for length, I showed on another issue that they don't get that long at high-scale. As I said there, you need to generate more than 4 IDs per millisecond, on a single machine, to get IDs longer than 12 chars. UUIDs take 16 bytes, 32 if you encode as strings so 12 is still a bargain.

@ai
Copy link
Collaborator

ai commented Jul 8, 2018

This library doesn’t have this API since it is dynamic ID length.

Use Nano ID, where you can change ID length.

@ai ai closed this as completed Jul 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants