Skip to content

Instantly share code, notes, and snippets.

@SeLub
Created November 10, 2025 09:18
Show Gist options
  • Select an option

  • Save SeLub/562c8cdc919ff762e535656b84656109 to your computer and use it in GitHub Desktop.

Select an option

Save SeLub/562c8cdc919ff762e535656b84656109 to your computer and use it in GitHub Desktop.

UUID vs CUID

UUID (Universally Unique Identifier)_ and CUID (Collision-resistant Unique Identifier) are both methods for generating unique identifiers, but they differ in their design and intended use cases.

UUID:
Definition:
A 128-bit number used to uniquely identify information in computer systems.

Characteristics:
- Designed for global uniqueness across distributed systems without central coordination.
- Standardized (RFC 4122) and widely adopted.
- Multiple versions exist (e.g., v1 based on MAC address and timestamp, v4 based on random numbers).
- Typically represented as a 36-character hexadecimal string with hyphens (e.g., xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx).

Advantages:
Strong guarantee of uniqueness, no central coordination required, standard format.

Disadvantages:
Can be long and less human-readable, not inherently sortable, potential performance impact due to size.

CUID:
Definition:
A unique identifier designed to be collision-resistant, sortable, and more compact than UUIDs.

Characteristics:
- Emphasizes collision resistance in distributed environments.
- Typically shorter than UUIDs (e.g., 24 characters by default in CUID2).
- Often includes a timestamp and a counter component to aid in uniqueness and sortability.
- CUID2, a newer iteration, uses a mix of numbers and full alphabet characters.

Advantages:
Shorter and more human-readable, sortable, designed for high collision resistance.

Disadvantages:
Less widely standardized than UUIDs, may not offer the same level of global uniqueness guarantee as UUIDs in all scenarios.

Key Differences and Considerations:

  • Uniqueness Guarantee:
    UUIDs aim for global uniqueness, while CUIDs prioritize collision resistance, especially in distributed systems.

  • Length and Readability:
    CUIDs are generally shorter and more human-readable than UUIDs.

  • Sortability:
    CUIDs are often designed to be sortable due to their timestamp component, which is not a primary feature of all UUID versions.

  • Standardization:
    UUIDs are a well-established standard, while CUIDs are more domain-specific.

Use Cases:

UUIDs are commonly used in databases, distributed systems, and any scenario requiring globally unique identifiers.
CUIDs are often favored in applications where shorter, sortable, and collision-resistant IDs are important, such as in front-end development or specific backend services.
The choice between UUID and CUID depends on the specific requirements of the application, including the need for global uniqueness, sortability, length, and performance considerations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment