MiniUtil field guide

UUID v4 vs UUID v7 vs ULID

Compare UUID v4, UUID v7, and ULID for randomness, sort order, database indexes, timestamp visibility, and ecosystem compatibility.

Short answer: Use UUID v4 for broadly compatible random IDs, UUID v7 for time-ordered standard UUIDs, and ULID when its compact sortable text form is an explicit requirement.

Randomness and ordering solve different problems

UUID v4 is random and reveals no creation time, but random inserts can scatter writes across a large database index. UUID v7 and ULID put a millisecond timestamp near the front, improving natural sort order while exposing approximate creation time.

Ordering does not guarantee monotonicity

Two IDs generated in the same millisecond need an additional strategy if their lexical order must exactly match generation order. Clock rollback, multiple machines, and implementation-specific random fields can also affect ordering.

Treat IDs as identifiers, not access controls

An unpredictable ID reduces casual guessing but does not authorize access. Apply authentication and object-level authorization regardless of the identifier format, and avoid encoding private meaning in IDs.

Quick comparison

FormatShapeOrderingBest fit
UUID v4128-bit UUID, 36-character canonical textRandomMaximum compatibility and no embedded time
UUID v7128-bit UUID, 36-character canonical textTime-ordered by designDatabase locality with UUID tooling
ULID128 bits, 26 Crockford Base32 charactersLexically time-sortableCompact readable strings with ULID ecosystem support