Live data from Hacker News

Sqids – Generate short unique IDs from numbers

sqids.org

61–70 of 249 posts

Re: Sqids – Generate short unique IDs from numbers

#61

I haven’t been able to find a case for this because ids either need to be unique or they’re not going to be large. If they’re unique, I’m using uuid or ulid (uuidv7 of tomorrow) as the sortable primary key type to avoid conflicts without using the db to generate and maintain sequences. Where do you have unique ids that aren’t the primary key? I would be more interested in a retrospectively unique truncated encoding f…

The idea is that you encode and decode database IDs with this. You wouldn't save them separately unless you were using it for a purpose other than shareable "identifiers" which don't leak significant amounts of database state. Imagine something like a link shortener where you want to provide a short link to users, but don't want it to just be a number.

Re: Sqids – Generate short unique IDs from numbers

#65
post #28

Sad that it is not for user ids

I think that's only if you don't want to leak user count when your ID is an autoincrement. Elsewhere people mention cryptographicly remapping integers, which could work (by itself, or before passing the ID to sqids).

Re: Sqids – Generate short unique IDs from numbers

#66
post #62

Why should you hide your user count?

The rate of change over time can be used against you; many people consider their businesses’ month-over-month growth (or lack thereof) to be private information.

“$WEBSITE did 50,000 signups a month during the beginning of the pandemic, but now struggles to sign up a thousand a week” is a story.

Re: Sqids – Generate short unique IDs from numbers

#67
post #27
post #12

Earlier quoted context omitted.

> it excludes letters used for profanity That doesn't seem possible. How would that work? > I looked at the implementation and it’s hardcoded to look for “bad” words. If you mean https://github.com/y-gagar1n/nanoid-good , that seems to be doing the same thing. In general, I'm a bit weary of solutions that "guarantee no bad words" – this is usually highly language-specific: One language's perfectly acceptable name is…

Omit vowels and you're 90% of the way there; omit the vowel-looking digits 0,1,3,4 and you're probably >99% of the way there.

fxck

Re: Sqids – Generate short unique IDs from numbers

#68
post #63

It would be great to have a quick primer on why this is better than what people typically homebrew, like base62 encoding a random number.

If you use a random number then you need to store it somewhere to map back to the original. Sqids is an encoding, you can decode the sqid back to the original without storage overhead.

Features like the profanity filter avoid creating URL routes like /user/cuntFh.

Cross language support allows interop between the encoder and decoder across microservices written in different languages.

Re: Sqids – Generate short unique IDs from numbers

#69
post #42

Earlier quoted context omitted.

I believe a big part of the idea is for the hash to be unpredictable as well. If I figure out you're using (36) then I know the next number 1234567891 is "kf12oj". Not the case with Sqids.

You can easily brute-force this. Sqids also says it's not good for sensitive data.

It looks like an easy brute force too, there's no compute-hard operations here. I guess you could scramble your alphabet? Otherwise Uk always comes after bM, etc.

Re: Sqids – Generate short unique IDs from numbers

#70
Side note: there are some business insights you can get from a company using serial ids.

i.e if you sign up and get user id 32588 and make another account a few days later, you can tell the growth rate of the company.

And this is possible with every resource type in the application.

I do wonder how much the url bar junk thing matters these days. I tend to use uulids (waiting on uuid v7 wide adoption), and they're a bit ugly, but most browsers hide most of the urls now anyway. The fact that there is a builtin time component comes in clutch sometimes (e.g. object merging rules).

Post reply on HN