For a message or order table, the difference between ULID and UUID v4 comes down to one property: ULID's lexicographic order equals its creation order.
UUID v4 : 550e8400-e29b-41d4-a716-446655440000 (random, 36 characters)
ULID : 01HZ3G7DZP5XA5Z4G5TQXW2Q7T (sortable, 26 characters)
Both are globally unique and both generate offline. The split shows up in three places: whether index writes stay sequential, whether logs aggregate by ID alone, and whether the holder can read the creation time. UUID v7 pursues the same idea with a standard shape, so it belongs in the comparison too.
ULID's construction: 48 bits of time, 80 bits of randomness
The first 48 bits are milliseconds since the Unix epoch, encoded as 10 Base32 characters. The remaining 80 bits are cryptographically random, encoded as 16 characters. The alphabet is Crockford Base32, which omits I/L/O/U so hand-copied values stay unambiguous.
Twenty-six characters exist because Base32 spends five bits per character; the first character therefore carries only two significant bits. So "10 characters of time plus 16 of randomness" is an encoding artifact, not a 48/80 split of the string. Decoding takes the first ten characters back to a millisecond value, and with it the ordering rule: compare time first, randomness only on a tie.
Four identifier families compared
UUID v4 is 36 dashed characters, unsortable, fully offline. ULID is 26 compact characters, millisecond-sortable, fully offline. UUID v7 matches ULID's capability in a standard 128-bit UUID that fits a native column. Snowflake-family values are short but depend on a worker ID.
ULID and v7 are near-equivalents; what separates them is encoding and standardisation, plus whether your column is a UUID type or a string. Snowflake buys storage efficiency by giving up coordination-free generation. Cross-node strict ordering is unavailable to all three except where an implementation adds coordination.
Monotonic generation inside one millisecond
Random bits generated within the same millisecond are unordered by construction, which still triggers page splits. Many implementations offer a monotonic mode: on a repeat call in the same millisecond, the random portion behaves as a counter until it overflows or the clock ticks.
That guarantee is per node only — the counter is process state, so concurrent writers on different hosts still interleave. A second edge is a clock moving backwards: now shrinking resets the counter and lexicographic order walks backwards, so a production implementation must either hold the last timestamp or refuse the rollback.
Why ordered keys suit B+ trees
InnoDB-style clustered indexes use the primary key as physical order. A random key inserts into the middle of a page, causing splits, extra lookups and random write amplification; an ordered key appends at the tail. At tens of millions of rows the difference in write throughput and cache locality is unmistakable.
That is the decision point: if you want globally unique plus roughly chronological, ULID or v7 fits database behaviour better than v4. Generate and compare with the ULID generator and UUID generator.
The privacy trade-off cuts both ways
Anyone holding a ULID knows when it was created. In log forensics that is a lifeline; exposed to a customer it is a weakness.
- User-facing identifiers such as order numbers or invite codes should use UUID v4 when time must stay hidden.
- Internal keys, database primary keys, logs and event IDs are better served by ULID.
- If the creation time itself is compliance-sensitive, encrypt it as its own field instead of leaking it through a sortable ID.
UUID v7 exposes millisecond time in exactly the same way, so the rule applies unchanged.
Quick selection rules
ULID for ordered relational keys, time-aggregated logs, short strings, offline generation. UUID v7 for the same needs where a standard UUID column or cross-system interop matters. UUID v4 for user-facing values that must not reveal time. Snowflake or database sequences when cross-node strict ordering is mandatory and a worker ID is available.
Reproducible Results
ULID's time ordering can be verified by hand — the timestamp portion is simply milliseconds in Crockford Base32:
CROCK = '0123456789ABCDEFGHJKMNPQRSTVWXYZ'
ts_ms = 1745126400000
print(''.join(CROCK[(ts_ms >> s) & 31] for s in range(45, -1, -5)))
# → 01JS8T7800 (timestamp part; the last 16 chars are random)
print(str(uuid.uuid4())) # → fully random, unordered
print(uuid.uuid5(uuid.NAMESPACE_DNS, 'example.com')) # → same input, same output (deterministic)
ULID sorts chronologically as a primary key, keeping B+ tree inserts sequential; a fully random UUIDv4 risks a page split on every insert. Deterministic versions such as uuid5 map the same name to the same value, which suits "one domain, one ID".