Comparison

UUID v7 vs UUID v4

Version 4 hides when it was created. Version 7 puts the millisecond in the identifier, which changes sort order and can change how an index grows.

UUID v4UUID v7
SpecificationRFC 9562 version 4RFC 9562 version 7
TimeNone48-bit Unix milliseconds
Random bits122, after version and variant74 on this site (12 + 62)
Text sortNot ordered by timeOrdered by millisecond
Same millisecondNot applicableRandom, not a counter, on this site
Reveals a clockNoYes, to millisecond precision

A B-tree on random version 4 keys tends to insert all over the index. Version 7 keys from a moving clock tend to arrive toward the recent side. That can mean fewer scattered page splits, but it depends on the table, the fill factor, and how many writers you have. It is not a guarantee that queries get faster.

Because the time is visible, do not put a v7 in a place where the creation time itself is sensitive. Neither version is a secret.

Questions

Which one is random?

Version 4 uses random bits apart from the version and variant. Version 7 on this site uses a millisecond timestamp plus 74 random bits.

Which one sorts by time?

Only version 7 puts time in the high bits, so the canonical text sorts by millisecond. Version 4 does not.

Does v7 replace v4?

No. Version 4 remains a normal choice when you do not want the time to be visible in the identifier.