-
Notifications
You must be signed in to change notification settings - Fork 182
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
KSUID order not predictable #73
Comments
Also, here in the README with the example of the cli tool:
But when using the first two ids the cli generated they are clearly not in natural order: node -e 'console.debug("0ujsszwN8NRY24YaXiTIE2VWDTS" < "0ujsswThIGTUYm2K8FjOOfXtY1K")'
false node -e 'console.debug("aaa" < "bbb")'
true |
This article states the following: https://blog.kowalczyk.info/article/JyRZ/generating-good-unique-ids-in-go.html
So I guess this means the generations of two successive ksuids must be apart about 1s until they really will be ordered by creation, is that correct ? |
You are correct, KSUIDs are roughly ordered but the default random generation we use does not guarantee absolute ordering. A strategy we've used in some place is to generate one KSUID then derive the next ones from it by incrementing its value, which then creates a locally ordered sequence of ids. |
@timo-klarshift In my experience of the library a delay of 3 seconds per K-SUID is a safe bet to guarantee ordering. I think the main feature is that they are K-Sortable, not that they are accurate on a per-second basis. If you need that I'd check out sonyflakes which are not always unique but will remain unique and sortable to millisecond precision. Hope that helps. |
This is really not a good approach if you want to create many of them in a high throughput system |
Hey there
The README states this:
I have the following code:
Running it like this
go test ./ -v -count=100 -run=TestKsuidOrder
results inI was expecting that
ksuid.New
is generating sequences which can be naturally ordered?If this is the expected behaviour which I see - then I guess the README should be more clear about that.
The text was updated successfully, but these errors were encountered: