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

recommendation for creating stripe-like prefixed identifiers #80

Open
charlie-maloney opened this issue Sep 11, 2024 · 2 comments
Open

Comments

@charlie-maloney
Copy link

charlie-maloney commented Sep 11, 2024

Hi,

Thanks for all your work on cuid2. I'm considering using this library as a way to generate IDs in our Postgres DB, and I had a couple questions regarding recommendations for usage in cuid2:

  1. I want to create stripe-like prefixed identifiers for my application (e.g. usr_ tz4a98xxat96iws9zmbrgj3a). Is this at as simple as concatenating the prefix with cuid ID or are there other considerations we must make?

  2. Would you recommend using this as the primary key in our DB? I see a lot of discussion around using monotonically increasing IDs (ints/big ints) as primary keys for performance reasons and having a separate entity ID for usage in APIs. My concerns with the latter approach are a) you still need to either index on the entity id or maintain a look-up table mapping entity IDs to primary keys and b) your primary keys in a sharded DB are no longer unique.

Any advice or considerations would be greatly appreciated. Thanks!

@tibotiber
Copy link

Hey @charlie-maloney, i'm about to do the same thing.

  1. I'm no expert in any way but going with a simple concat. To me it's just adding a piece of non-entropic content and can't corrupt the benefits existing in the id. It leaks the type of data, which is the intent here anyway. I'd compare it to the 4 present to identify uuidv4 in a way.
  2. There is quite a bit on this at in the README, does it help?

@charlie-maloney
Copy link
Author

Hey @tibotiber -- thanks for following up and letting me know! I came to the same conclusion and figured that a simple concat would be the way to go.

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