About uuid generator
A UUID is a 128-bit identifier that is unique for practical purposes, so different systems can create IDs without coordinating. Version 4 UUIDs are random.
Format
Written as 32 hex digits in the pattern 8-4-4-4-12, for example 3f2504e0-4f89-41d3-9a0c-0305e82c3301. The 4 at the start of the third group marks version 4.
When to use them
- Database primary keys when records are created in many places.
- Request and correlation IDs in logs.
- File names that must not clash.
Not secrets
UUIDs identify things; they are not authentication tokens. For access tokens use a dedicated secure token generator.
How unique is unique
A version 4 UUID has 122 random bits, giving about 5.3 × 10³⁶ possible values. You could generate a billion a second for decades and the chance of a repeat would still be negligible. They are written as 36 characters, with dashes in the 8-4-4-4-12 pattern.
Database tip
Random UUIDs used as primary keys can fragment indexes. Time-ordered identifiers such as UUID v7 or ULID keep new rows together and are friendlier to databases.
