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

How does it compare to ULID? #42

Open
v3rmin opened this issue Oct 19, 2018 · 5 comments
Open

How does it compare to ULID? #42

v3rmin opened this issue Oct 19, 2018 · 5 comments

Comments

@v3rmin
Copy link

v3rmin commented Oct 19, 2018

Spec for ulid: https://github.com/ulid/spec

@rs
Copy link
Owner

rs commented Oct 19, 2018

ULID requires locking if you need to use it concurrently.

@wotzhs
Copy link

wotzhs commented Oct 20, 2021

many years later, I think another major difference compare to ULID is xid is only up to 1 second precise, meaning sorting is only possible within the same second, whereas ULID is up to millisecond precise.

@rs
Copy link
Owner

rs commented Oct 20, 2021

IDs from the same second have a local monotonic incrementing random inited counter, so they will still sort well when generated on the same machine/process.

@saraf-gaurav
Copy link

saraf-gaurav commented Jun 14, 2024

xid seems relatively better if the priority is conciseness, indexing-performance and zero-configurability. But I am not too sure if the locking argument holds true @rs :

ULID requires locking if you need to use it concurrently.

According this comparison of Golang ID packages actually https://github.com/oklog/ulid also achieves fast lock-free concurrent ULID generation

Besides millisecond precision, ULID also enjoys broader support due backward compatibility with UUID columns e.g. Cockroach DB has a builtin function to generate ULIDs for PKs

For a distributed DB like Cockroach DB with xid generated in the application layer over distributed containers / serverless functions sharing a DB cluster, @rs are there any reasons you would still recommend xid over ULID all things considered, especially when there's no guarantee that the xid will be generated on the same machine/process?

@rs
Copy link
Owner

rs commented Jun 14, 2024

For concurrency ULID requires a lock while xid uses an atomic counter as a workaround. Depending on the application, this can be a factor. Conciseness is another.

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

4 participants