ulid VS ksuid

Compare ulid vs ksuid and see what are their differences.

ulid

Universally Unique Lexicographically Sortable Identifier (ULID) in Go (by oklog)

ksuid

K-Sortable Globally Unique IDs (by segmentio)
Our great sponsors
  • WorkOS - The modern identity platform for B2B SaaS
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • SaaSHub - Software Alternatives and Reviews
ulid ksuid
11 38
4,061 4,628
1.8% 2.6%
4.3 3.1
15 days ago 6 months ago
Go Go
Apache License 2.0 MIT License
The number of mentions indicates the total number of mentions that we've tracked plus the number of user suggested alternatives.
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.

ulid

Posts with mentions or reviews of ulid. We have used some of these posts to build our list of alternatives and similar projects. The last one was on 2023-06-28.

ksuid

Posts with mentions or reviews of ksuid. We have used some of these posts to build our list of alternatives and similar projects. The last one was on 2023-12-12.
  • Zero Downtime Postgres Upgrades
    4 projects | news.ycombinator.com | 12 Dec 2023
    OP here - we avoid sequences in all but one part of our application due to a dependency. We use [KSUIDs][1] and UUID v4 in various places. This one "gotcha" applies to any sequence, so it's worth calling out as general advice when running a migration like this.

    [1]: https://segment.com/blog/a-brief-history-of-the-uuid/

  • Bye Sequence, Hello UUIDv7
    8 projects | news.ycombinator.com | 1 Oct 2023
    Feels like a spiritual successor to the ksuid [1] lib which I first heard of used in conjunction with DynamoD.

    [1]: https://github.com/segmentio/ksuid which has very similar use cases.

    8 projects | news.ycombinator.com | 1 Oct 2023
    UUID v4 isn't large enough to prevent collisions, that is why segment.io created https://github.com/segmentio/ksuid which is 160bit vs the 128bit of a UUIDv4.
    8 projects | news.ycombinator.com | 1 Oct 2023
    UUIDv7 is a nice idea, and should probably be what people use by default instead of UUIDv4.

    For the curious:

    * UUIDv4 are 128 bits long, 122 bits of which are random, with 6 bits used for the version. Traditionally displayed as 32 hex characters with 4 dashes, so 36 alphanumeric characters, and compatible with anything that expects a UUID.

    * UUIDv7 are 128 bits long, 48 bits encode a unix timestamp with millisecond precision, 6 bits are for the version, and 74 bits are random. You're expected to display them the same as other UUIDs, and should be compatible with basically anything that expects a UUID. (Would be a very odd system that parses a UUID and throws an error because it doesn't recognise v7, but I guess it could happen, in theory?)

    * ULIDs (https://github.com/ulid/spec) are 128 bits long, 48 bits encode a unix timestamp with millisecond precision, 80 bits are random. You're expected to display them in Crockford's base32, so 26 alphanumeric characters. Compatible with almost everything that expects a UUID (since they're the right length). Spec has some dumb quirks if followed literally but thankfully they mostly don't hurt things.

    * KSUIDs (https://github.com/segmentio/ksuid) are 160 bits long, 32 bits encode a timestamp with second precision and a custom epoch of May 13th, 2014, and 128 bits are random. You're expected to display them in base62, so 27 alphanumeric characters. Since they're a different length, they're not compatible with UUIDs.

    I quite like KSUIDs; I think base62 is a smart choice. And while the timestamp portion is a trickier question, KSUIDs use 32 bits which, with second precision (more than good enough), means they won't overflow for well over a century. Whereas UUIDv7s use 48 bits, so even with millisecond precision (not needed) they won't overflow for something like 8000 years. We can argue whether 100 years us future proof enough (I'd argue it probably is), but 8000 years is just silly. Nobody will ever generate a compliant UUIDv7 with any of the first several bits aren't 0. The only downside to KSUIDs is the length isn't UUID compatible (and arguably, that they don't devote 6 bits to a compliant UUID version).

    Still feels like there's room for improvement, but for now I think I'd always pick UUIDv7 over UUIDv4 unless there's an very specific reason not to.

  • You Don't Need UUID
    13 projects | news.ycombinator.com | 11 Sep 2023
  • Type-safe, K-sortable, globally unique identifier inspired by Stripe IDs
    19 projects | news.ycombinator.com | 28 Jun 2023
    Assuming you don't need to use UUIDv7 (or any UUID's) then https://github.com/segmentio/ksuid provides a much bigger keyspace. You could just append a string prefix if you wanted to namespace, but the chance of collisions of a KSUID is many times smaller than a UUID of any version.
    19 projects | news.ycombinator.com | 28 Jun 2023
    Why use this instead of appending a string to https://github.com/segmentio/ksuid which has a much larger keyspace?
  • Unexpected downsides of UUID keys in PostgreSQL
    6 projects | news.ycombinator.com | 22 Jun 2023
    If size isn't an issue it seems so. I know of one implementation that uses wall clock to get a "close enough" sorting https://github.com/segmentio/ksuid
    6 projects | news.ycombinator.com | 22 Jun 2023
    KSUID's are have temporal-lexicographical order plus 128 bits of entropy, which is more than UUIDv4.

    https://github.com/segmentio/ksuid

  • What Happened to UUIDv2?
    2 projects | dev.to | 16 Jan 2023
    Interesting in more history of UUIDs? Twilio Segment's blog has an amazing history lesson about how they came to be.

What are some alternatives?

When comparing ulid and ksuid you can also consider the following projects:

nanoid - A tiny and fast Go unique string generator

ulid - Universally Unique Lexicographically Sortable Identifier (ULID) in Python 3

pg-ulid - ULID Functions for PostgreSQL

nanoid - A tiny (124 bytes), secure, URL-friendly, unique string ID generator for JavaScript

xid - xid is a globally unique id generator thought for the web

ulid-mssql - Implementation of ULID generator For Microsoft SQL Server

python-ksuid - A pure-Python KSUID implementation

uuid7 - UUID version 7, which are time-sortable (following the Peabody RFC4122 draft)

cuid - Collision-resistant ids optimized for horizontal scaling and performance.

Hasura - Blazing fast, instant realtime GraphQL APIs on your DB with fine grained access control, also trigger webhooks on database events.

sonyflake-rs - 🃏 A distributed unique ID generator inspired by Twitter's Snowflake.

gouid - Fast, dependable universally unique ids