3 ms·
I really like ULID for this problem (e.g: https://github.com/ahawker/ulid https://github.com/ahawker/ulid) - similar characteristics to UUID: same number of by
by BiteCode_dev 4y ago
I really like ULID for this problem (e.g: https://github.com/ahawker/ulid https://github.com/ahawker/ulid)
- similar characteristics to UUID: same number of bytes, equivalent collision resistance, hard to guess, etc.
- start with a date, is monotonic, and is lexicographically sortable: not only it has great locality but sorting is super easy and most code get it right by default.
- can be created from an existing date or uuid, and exported to a uuid, so there is a migration path.
- you get the creation date for free, which is always nice. As a bonus, you can now use the uuid as a base for dispatching, bracketing, sharding, etc.
- Vanderson 4y agoSame here. I am really, really hopeful there is a drop in replacement for ULIDs if they ever get abandoned.
- BiteCode_dev 4y agoIt's not a very complicated algorithm, they can't get abandoned, you can always recode it, and use it.
- ywain 4y agoI expect the new UUID formats (https://datatracker.ietf.org/doc/html/draft-peabody-dispatch-new-uuid-format https://datatracker.ietf.org/doc/html/draft-peabody-dispatch...) to fill that need once they get standardized and made available in standard libraries or popular packages.
- Sytten 4y agoThe last draft expired without any consensus so I dont have high hopes for this one. We will see.
- BiteCode_dev 4y agoEspecially UUID7, it it becomes standard, ULID won't be necessary anymore, unless you want a shorted text representation. But ULID exists right now, UUID7 is still in the making.
- Sytten 4y agoAlso a fan of this format though I wish it was native to postgres so we dont have to convert to UUID for storage (maybe a custom type would do it). For reference here is my plpgsql implementation: https://gist.github.com/Sytten/8fa334e8a5de5d49924c794811a809fb https://gist.github.com/Sytten/8fa334e8a5de5d49924c794811a80...
- canadiantim 4y agoisn't UUID v7 basically ULID? So you can just use UUID v7 for same effect
- Macha 4y agoUUIDv7 is still a draft, but seems relatively uncontroversial so will likely be accepted. Still a lot of libraries and systems with uuid support are hesitant to add v7 support until it got gets finalised, so for now ULID has more widespread support. They're basically the same, except uuidv7 has a few bits less randomness for UUID fields like version and variant, so I'm sure in 5-10 years the answer will be just use v7, but for the time being, for those use cases I'd stick to ULID.
- koolba 4y ago> you get the creation date for free, which is always nice Leaking information is not “always nice”. For example using that as an id for a medical record would give you specific information for the date of diagnosis or treatment.
- BiteCode_dev 4y agoSure. And a extra $100000 in your bank account isn't "always nice". It may get you flagged by the IRS and you may have more chance to now be inspected. They are always exceptions. "always nice" is a matter of speaking. There are very few things that are always true, and I assume reader know that.
- lcnPylGDnU4H9OF 4y agoWhile I don't disagree with this statement, it also seems to make sense to me that you were corrected. Words mean things and if you use a word in a way that someone disagrees with, there you go. Probably just don't take the correction so personally. I think quite often it is the case that a person "corrects" in this manner (remember: this is a public online forum) because they want the thing they say to be visible alongside the thing they responded to. Not you, but instead the next reader, will read what you wrote and then build their medical/finance/legal application thinking that the availability of additional metadata can't possibly have any downsides. But (perhaps) now that reader will read the response and not make said mistake.
- pwinnski 4y ago> "always nice" is a matter of speaking. Incorrectly. It's a matter of speaking incorrectly.
- BiteCode_dev 4y agoYou remind me of the TV bits in the movie "the invention of lying". They can't lie, so they are perfectly correct.
- 4y ago
- CMCDragonkai 4y agoWe evaluated ULID but we wanted something that is future proof for our decentralised secret sharing system. So we implemented UUIDv7 in TypeScript called `IdSortable` https://github.com/MatrixAI/js-id https://github.com/MatrixAI/js-id It allows strict monotonic IDs when you provide it the previously generated ID. The resulting data structure is a Uint8Array making it easy to put into binary structures. Can also be used as a key inside any POJO record.