UUID v4 and UUID v7
UUIDs (Universally Unique Identifiers) are 128-bit identifiers that are guaranteed to be unique across space and time. They are commonly used in distributed systems where unique IDs need to be generated without coordination between nodes. RFC 9562 recommends UUID v7 over older time-based versions when applications benefit from creation-time ordering.
UUID Format
A standard UUID looks like: 550e8400-e29b-41d4-a716-446655440000
It consists of 32 hexadecimal digits displayed in 5 groups separated by hyphens, in the form 8-4-4-4-12 for a total of 36 characters.
Common Use Cases
- Database primary keys
- Session identifiers
- Distributed system identifiers
- File naming
- API request correlation IDs
Choosing a version
Use UUID v4 when you want an opaque random identifier. Use UUID v7 for database keys, event IDs, and logs where roughly chronological sorting improves index locality and operational debugging.