· articles · 4 min read

By Ankit Jain

ULID vs UUID

Compare UUID and ULID to understand their unique properties and use cases. UUID4 offer high randomness and are ideal for cryptographic purposes. ULIDs provide lexicographical sorting and readability, making them suitable for ordered data and logs. Discover which fits your needs.

ULID (Universally Unique Lexicographically Sortable Identifier) and UUID (Universally Unique Identifier) both have unique properties. If you aren’t familiar with ULID, check out this article. Here are some key differences and similarities between ULID and UUID. Both are suited for specific requirements, and the table below helps you compare their properties. Choose the one that best fits your use case.

Common Properties

ParameterULIDUUID
Length26 characters36 characters
StructureTimestamp + Random ComponentRandom or Timestamp-based
SortabilityLexicographically sortableNot sortable
ReadabilityMore readableLess readable
Collision ProbabilityExtremely lowExtremely low
Character SetBase32 (0-9, A-Z, excluding I, L, O, U)Hexadecimal (0-9, a-f)
Timestamp PrecisionMillisecondsN/A or variable (depending on UUID version)
Storage RequirementLess storage space (26 chars)More storage space (36 chars)
Generation SpeedFastFast
Global UniquenessYesYes
Used ForScenarios requiring order and readabilityGeneral purpose, wide adoption
Best forScenarios requiring uniqueness and ordering by timeApplications where sortability is not a priority
PerformanceFast and efficient generationFast generation
Few Samples01HY3S6C1MKYHA00748TB7A1MW , 01HY3S6C1NG3YDJR80H7N2CPTV, 01HY3S6C1N8ZWQMKE9CFTGBKET , 01HY3S6C1NDQ0PZP0YSA4VSA0E, 01HY3S6C1NS4TM2R10PZ6WN3RTd914dc77-89a7-4706-b9b8-b5d20f2de05a, ee1de5f0-95a9-4aea-9fd2-d184108d947e, 1bb28cad-2a55-46ce-9706-f53cff521170, a1b525b8-0fe8-47ee-8092-f9f7a7464740, a3452a4c-d288-4619-96dd-d95fddf30aa5

Unique in Space vs Unique in Time

When comparing ULID and UUID, it’s important to understand the concepts of “unique in space” and “unique in time”.

  • Unique in Space: An identifier that is unique in space ensures that no two identifiers are same when generated across different systems. This property is crucial in distributed systems where multiple nodes might generate identifiers independently.
  • Unique in Time: An identifier that is unique in time ensures that no two identifiers are same when generated at the exact moment on the same system. This property is useful in multi-threaded and multi-core processors.

Performance Analysis

  • ID Generation Benchmarks: Benchmarks show that ULID generation is fast and efficient. In many cases, ULID generation can be faster than UUID generation due to its simpler structure.
  • Speed Comparisons with UUID: While both ULIDs and UUIDs are fast to generate, ULIDs have an edge in scenarios requiring sorting, as they are designed to be lexicographically sortable.
  • Storage Requirements: ULIDs require less storage space compared to UUIDs due to their shorter length (26 characters vs. 36 characters). This can lead to storage savings, especially in large databases.
  • Possible Combinations and Scalability: With 48 bits for the timestamp and 80 bits for randomness, ULIDs offer a vast number of unique combinations, making them highly scalable for most applications.
  • Real-World Applications: ULIDs are used in various applications, such as:
    • Logging systems: Ensuring log entries are ordered by time.
    • Databases: Creating unique and sortable identifiers for records.
    • Distributed systems: Generating unique IDs without central coordination.

UUID v7

UUID v7 is a new variant of UUIDs that incorporates the current timestamp to ensure orderability while maintaining randomness. It was introduced to address the limitations of previous UUID versions in scenarios requiring ordered data.

Key Features of UUID v7:

  • Timestamp-based: Uses the current timestamp as part of the identifier.
  • Sortable: Ensures lexicographical order, making it suitable for databases and logs.
  • Randomness: Includes random bits to minimize collisions.
  • Length: Consistent with other UUIDs at 36 characters.

Comparison of UUID v7 and ULID

ParameterUUID v7ULID
Length36 characters26 characters
SortabilityYesYes
RandomnessHighModerate
Timestamp-basedYesYes
ReadabilityModerateHigh
CollisionProbabilityExtremely low Extremely low
Use CasesDatabases, logsDatabases, logs, general-purpose identifiers

Applications

  • UUID v7: Ideal for systems requiring unique, time-ordered identifiers with high randomness, such as distributed databases and logging systems.
  • ULID: Best suited for applications needing shorter, sortable, and user-friendly identifiers.

Database Support for UUID v7

This table provides an overview of UUID v7 support across popular database systems, categorized as native support, plugin/library availability, or the necessity for custom code implementation.

DatabaseSupport for UUID v7Version
PostgreSQLNative support (requires setup)14+
MySQLPlugin/libraries available8.0+
MongoDBCustom code4.0+
SQLiteCustom code3.35.0+
OraclePlugin/libraries available19c+
Microsoft SQL ServerLimited support (custom code)2019+
CassandraNo native support; custom code3.11+
RedisNo native support; custom code6.0+
Neo4jCustom code4.0+
CockroachDBNative support21.1+

Cryptographic Usecases

In a cryptographic use case, UUIDs are generally preferred over ULIDs. Here’s why:

UUID

  • Randomness: UUID version 4, which is randomly generated, offers high entropy and randomness, making it suitable for cryptographic purposes where unpredictability is crucial.
  • Standardization: UUIDs are a well-established standard (RFC 4122) and are widely recognized and used in various cryptographic protocols and systems.

ULID

  • Predictability: ULIDs contain a timestamp, which could introduce predictability in the identifier. For cryptographic use cases, predictability can be a vulnerability.
  • Random Component: While ULIDs have an 80-bit random component, the presence of the timestamp component makes them less suitable for applications requiring high entropy and complete randomness.

[Top]

Back to Blog