· articles · 4 min read

By Ankit Jain

When Should ULID Not Be Used?

There are specific scenarios where using ULIDs might not be the best choice. These are high volume write systems or cryptographic requirements. Let's explore these situations in detail.

The Universally Unique Lexicographically Sortable Identifier (ULID) has gained popularity recently as an alternative to UUIDs due to its readable format and sortable nature. However, ULIDs are not a one-size-fits-all solution. There are specific scenarios where using ULIDs might not be the best choice. Let’s explore these situations in detail.

Understanding ULIDs

A ULID is a 128-bit identifier that consists of two main parts: a 48-bit timestamp and an 80-bit random component. This structure allows ULIDs to be lexicographically sortable based on their timestamp component, making them useful in various applications. ULIDs offer advantages such as readability, sortability, and ease of use in distributed systems.

Scenarios Where ULIDs Might Not Be Suitable

High Volume Write Systems

In high-volume write systems, such as those handling massive streams of data or real-time logging, ULIDs can become problematic. The timestamp component of the ULID can create “hot spots” in the database, where a significant number of write operations are concentrated around the current timestamp. This can lead to uneven distribution of data, causing performance bottlenecks and reducing the efficiency of the database.

Cryptographic Security Requirements

If your application requires cryptographically secure identifiers, ULIDs are not the best choice. While ULIDs provide a level of randomness, they are not designed to meet cryptographic security standards. The randomness in ULIDs is sufficient for general-purpose uniqueness but does not provide the security guarantees needed for sensitive applications. In such cases, using cryptographically secure UUIDs (version 4) or other secure identifier schemes is recommended.

Compatibility with UUID-Dependent Systems

Many existing systems and protocols are built around UUIDs, particularly UUID version 4. If you are working in an ecosystem that heavily relies on UUIDs, integrating ULIDs can cause compatibility issues. For example, some libraries, databases, and services expect UUIDs in a specific format and may not handle ULIDs correctly. This can lead to errors and increased complexity in your system integration efforts.

Sorting and Indexing Concerns

While ULIDs are designed to be sortable, there are scenarios where this feature might not be beneficial. For instance, if your application relies on random distribution for performance reasons, the sortable nature of ULIDs might cause problems. The timestamp component can lead to clustering of similar IDs, affecting the performance of indexes and queries. In such cases, purely random identifiers like UUID version 4 might be more suitable.

Legacy Systems Integration

Integrating ULIDs into legacy systems can be challenging. Legacy systems often have established patterns and data structures that expect specific formats for identifiers. Introducing ULIDs might require significant changes to these systems, leading to increased development time and potential bugs. In such scenarios, sticking with the existing identifier format, such as UUIDs, can be more pragmatic.

Case Studies and Examples

Case Study 1: High Volume Write System

A company implemented ULIDs for their logging system to leverage the sortability feature. However, they soon encountered performance issues due to write hotspots around the current timestamp. The database struggled with uneven load distribution, leading to slower writes and increased latency. Switching back to UUID version 4, which offered a more uniform distribution, resolved the performance bottlenecks.

Case Study 2: Cryptographic Security

An application handling financial transactions required secure and unique transaction IDs. Initially, ULIDs were chosen for their readability and sortability. However, security audits revealed that ULIDs did not meet the required cryptographic standards. The team switched to UUID version 4, which provided the necessary security guarantees, ensuring compliance with industry standards.

Alternatives to ULIDs

When ULIDs are not suitable, there are several alternatives to consider:

  • UUIDs: Universally Unique Identifiers (UUIDs) come in different versions, with version 4 being widely used for its randomness. UUIDs are a standard choice for generating unique identifiers.
  • Snowflake IDs: Developed by Twitter, Snowflake IDs are 64-bit unique identifiers that include a timestamp, machine ID, and sequence number. They are optimized for distributed systems requiring high-throughput ID generation.
  • Other Unique Identifier Systems: Depending on your specific needs, other custom or third-party identifier systems might be more appropriate. Consider the requirements of your application and the strengths and weaknesses of each identifier scheme.

ULIDs offer several advantages when they picked for the right use-case, however, they are not always the best choice. High volume write systems, cryptographic security requirements, compatibility with UUID-dependent systems, sorting and indexing concerns, and legacy systems integration are scenarios where ULIDs might not be suitable. As a system’s architect, understanding the limitations and alternatives will help you make informed decisions when choosing the right identifier for your application.

[Top]

Back to Blog