Member-only story
ULID: The Ultimate Solution for Unique, Ordered, and Efficient Identifiers!
ULID: Universally Unique Lexicographically Sortable Identifier
UUID: Universally Unique Identifier
1. Why not choose UUID
UUID currently has 5 versions:
- Version 1: Impractical in many environments because it requires access to a unique, stable MAC address, making it vulnerable to attacks.
- Version 2: Replaces the first four bits of the timestamp with POSIX UID or GID, facing similar issues as version 1.
- Version 3: Generated based on the MD5 hash algorithm, requiring a unique seed for generating randomly distributed IDs, which could lead to fragmentation in many data structures.
- Version 4: Generated based on random or pseudo-random numbers, providing no additional information other than randomness.
- Version 5: Generated using the SHA-1 hash algorithm, also requiring a unique seed for generating randomly distributed IDs, which could lead to fragmentation in many data structures.
The most commonly used version among these is UUID4, but even though it's random, there's still a risk of conflicts. Unlike UUIDs, which are either based on random numbers or timestamps, ULID is based on both timestamps and random numbers. The timestamp is accurate to the millisecond, with 1.21e + 24 random numbers per millisecond, eliminating the risk of conflicts. Additionally, ULIDs are more friendly when converted to strings compared to UUIDs.