UUID v4, v7 and ULID Compared, and Which to Use as a Database Key
An identifier you can create without asking the database lets many systems create records at the same time without clashing. The kind you choose affects performance, though.
The differences
- v4 is entirely random, with no order.
- v7 puts the time first, so it sorts by creation time.
- ULID follows a similar idea to v7 but is written as a shorter string.
Why time order matters
A fully random key scatters inserts across a database index. v7 mostly appends at the end, so it is often a better key than v4 for large tables.
Tool features
- Generate thousands at a time.
- Options for upper case, no hyphens and braces.
- Inspect an existing UUID or ULID to see its version and embedded time.
A caution
v7 and ULID reveal when they were created. If you do not want to expose time, use v4.