paralleldrive / cuid

Collision-resistant ids optimized for horizontal scaling and performance.
Other
3.42k stars 123 forks source link

Can we make it shorter? #219

Closed Sjoerd82 closed 1 year ago

Sjoerd82 commented 3 years ago

To support offline clients I'm contemplating converting my table's integer PK's (PostgreSQL 12) to CUID's. I still don't very much enjoy the idea of switching out those short and sweet integers for a larger text string, but I don't seem to have too much choice. But I'd like to keep them as short as possible.

  1. Can the CUID be shorter, given the following constraints:

    • It's not used for HTML identifiers, we can loose the leading 'c' (that's an easy one, we can just slice it off the string)
    • Clients can really not create more than 1 CUID per second, and even that is a stretch, so we could probably loose the counter (or a counter of 1 digit), given that the resolution of the timestamp is 1 second (the string is the unix epoch radix 36).
    • Security is not required, it's OK if the resulting CUID is guessable. Could this safely reduce the size of the random part?
  2. Would it make sense for this project to offer such a shortened version? You already provide a slug option, how about this variant?

On a sidenote... In the docs it's written that the client fingerprint is based (among other things) on the first chars of the agent string. But that's something with almost no variation between clients: Mozilla, Chrome, etc.. Or am I missing something here?

tbjgolden commented 3 years ago

@Sjoerd82 I agree with many of your points - but I would suspect that it would be unwise to change so many core principles to reach the aim of a shorter uid within this project - but if you were interested in developing a variant I'd be for it

there's also the .slug() method that makes it a little shorter for you

ericelliott commented 3 years ago

I'm open to an alternate slug implementation. I was never thrilled with the one we have.

ericelliott commented 1 year ago

I have a new implementation of cuid coming that will make it possible to create arbitrary-length cuids.

ericelliott commented 1 year ago

Fixed in Cuid2. Cuids now support arbitrary lengths.