pg_idkit
cuid2
pg_idkit | cuid2 | |
---|---|---|
8 | 15 | |
307 | 1,849 | |
5.2% | 6.2% | |
8.6 | 4.1 | |
2 months ago | 2 months ago | |
Rust | JavaScript | |
Apache License 2.0 | MIT License |
Stars - the number of stars that a project has on GitHub. Growth - month over month growth in stars.
Activity is a relative number indicating how actively a project is being developed. Recent commits have higher weight than older ones.
For example, an activity of 9.0 indicates that a project is amongst the top 10% of the most actively developed projects that we are tracking.
pg_idkit
-
Shrink UUIDs with PostgreSQL or Ruby
Unfortunately, as of PostgreSQL 16, UUIDv7 are not yet supported out of the box. For the time being, use an extension such as pg_uuidv7 or pg_idkit to generate UUIDv7 e.g. as default primary key when you CREATE new records.
-
UUIDv7 is coming in PostgreSQL 17
If you like this (I do very much), you might also like pg_idkit[0] which is a little extension with a bunch of other kinds of IDs that you can generate inside PG, thanks to the seriously awesome pgrx[1] and Rust.
[0]: https://github.com/VADOSWARE/pg_idkit
[1]: https://github.com/pgcentralfoundation/pgrx
- Pg_idkit: A Postgres extension for generating popular UUIDs
-
Bye Sequence, Hello UUIDv7
Yup this is one of the reasons I put together a light extension for this:
https://github.com/VADOSWARE/pg_idkit
There are a lot of options for UUID extensions (lots of great pure SQL ones!), but I wanted to get as many ID generation strategies in one place
Also note that native UUID v7 is slated to land in pg17:
https://commitfest.postgresql.org/44/4388/
- Pg_idkit: Postgres Extension for Generating UUIDs
-
ULIDs and Primary Keys
https://github.com/ulid/spec/issues
I went through this exploration a while back for a new project and decided on uuidv7s, which are binary compatible with ULIDs but will likely find more support as they get added to the original UUID RFC.
Either UUIDv7 or XIDs seem like better choices than ULIDs for new projects.
* Supabase on different primary key considerations: https://supabase.com/blog/choosing-a-postgres-primary-key
* Postgres extension for generating various kinds of IDs: https://github.com/VADOSWARE/pg_idkit
-
Introducing pg_idkit: A Postgres extension for generating UUIDs
I also made an issue in the repo so eventually I should get to expanding the benchmark set as well.
cuid2
-
The UX of UUIDs
The CUID readme [1] explains that there's no real point to K-sortable on modern hardware:
[1] https://github.com/paralleldrive/cuid2?tab=readme-ov-file#no...
-
Bye Sequence, Hello UUIDv7
There's a comparison in the README of the project:
https://github.com/paralleldrive/cuid2#the-contenders
Some of the arguments mentioned are explained elsewhere in the README, others are assumed.
One argument standing out for me is the lack of collision-resistance for UUIDv4 which is surprising for me and I didn't spot any sources for that argument.
Another argument is the entropy source where they go about that Math.random is not reliable as a single entropy source but glimpsing at the source code, they sprinkle the CUID with Math.random data.
I am no expert in ID security, so I am not qualified to speak about the validity of their arguments, only that there's insufficient information to validate without prior knowledge about the problem domain.
-
You Don't Need UUID
I'm recently finding cuid2 to be the best of these alternative GUIDs. They seem to have all of the benefits for what you would want to use a GUID for, but none of the drawbacks of existing implementations.[1]
[1]: https://github.com/paralleldrive/cuid2#the-contenders
-
Cuid2 - Secure, collision-resistant ids optimized for horizontal scaling and performance. Next generation UUIDs.
I've just released v2.0.0 of my cuid2 python port. The original cuid2 package comes from JS world by ParallelDrive. They have a lot of the reasons to use Cuid2 posted in their repo, including
-
I "did my own research" and "AI" is not taking my job any time soon.
I recently wrote a Go implementation of CUID2 because I could not find an existing one. It is not hello-world, but it is not duff's device either, which by the way neither could explain what it did from just the raw code in isolation.
-
I'm making a hashing function to hash user ids for a hobby app and would love some feedback
I think this implementation is the original one. It has the following to say about why it exists. And what it is good for:
-
I've created long guide regard modern and old algorithms for Identifiers like ULID, UUID, slug and others.
There's also https://github.com/paralleldrive/cuid2 which likely should be added to this as it is likely one of the better ones out there now.
-
How to ensure that we get 100% unique id in postgres with node js and prisma
If you're using prisma then you can use CUID or CUID2 to manually generate it.
- Cuid2 – Secure, collision-resistant ids optimized for scaling and performance
- Cuid2: Next Generation GUIDs
What are some alternatives?
postgresql-uuid-generate-v7
diesel - A safe, extensible ORM and Query Builder for Rust
ksuid - K-Sortable Globally Unique IDs
cube.js - 📊 Cube — The Semantic Layer for Building Data Applications
nanoid - A tiny (124 bytes), secure, URL-friendly, unique string ID generator for JavaScript
dxid - A better and safer way to display your primary keys in urls or in your app
pgx - Build Postgres Extensions with Rust! [Moved to: https://github.com/tcdi/pgrx]
typeid - Type-safe, K-sortable, globally unique identifier inspired by Stripe IDs
readyset - Readyset is a MySQL and Postgres wire-compatible caching layer that sits in front of existing databases to speed up queries and horizontally scale read throughput. Under the hood, ReadySet caches the results of cached select statements and incrementally updates these results over time as the underlying data changes.
cuid2 - Next generation GUIDs. Collision-resistant ids optimized for horizontal scaling and performance.