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

NodeBits & StepBits change #26

Closed
WeiWeiWesley opened this issue May 28, 2020 · 2 comments
Closed

NodeBits & StepBits change #26

WeiWeiWesley opened this issue May 28, 2020 · 2 comments

Comments

@WeiWeiWesley
Copy link

Would it possible that two different nodes created by two different NodeBits produce the same snowflakeID in the same time?

snowflake.NodeBits = 18
snowflake.StepBits = 7
a, _ := snowflake.NewNode(1)

snowflake.NodeBits = 14
snowflake.StepBits = 8
b, _ := snowflake.NewNode(2)

//a.Generate() == b.Generate() ?
@bwmarrin
Copy link
Owner

Without a bit of testing or a lot more thinking, I'm not sure 100% that you couldn't find some whacky mixture of node bits and step bits where you could create the same ID, though I think it's very unlikely. They would have to be made during the exact same millisecond and somehow have the node, and step bits be aligned too.

I would say, the uniqueness guarantee is for ID's created with the same NodeBits and StepBits settings.

You example above isn't valid though, the NodeBits + StepBits cannot be more than 22 total, that's the amount of space available to them.

@WeiWeiWesley
Copy link
Author

Thanks your reply. In theory, It will be a tiny chance to get the same id when stepBits run out in the same millisecond. Yes, it's better to create snowflakeID with same NodeBits and StepBits settings at the same project or cluster.

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

2 participants