Choose an ID for the job
Randomness, ordering and compactness solve different problems. Select them deliberately.
Version 4 prioritizes random identifiers
UUID v4 carries random bits plus fixed version and variant bits in the standard UUID structure. It is widely recognized and independent of a central allocator, but random insertion order may not be ideal for every database index.
The generator uses a maintained UUID implementation, which obtains secure randomness and can use native support. A small uniqueness smoke test is useful for finding integration mistakes, but it is not a mathematical proof that collisions cannot happen.
Version 7 carries time
UUID v7 places a Unix timestamp in milliseconds near the start of the UUID. It can improve time-oriented ordering, subject to the comparison semantics of your database. It also reveals approximate creation time, which can be undesirable for publicly visible identifiers.
Do not treat ordering as a distributed consensus clock. Clock differences, library behavior and same-millisecond generation matter. Confirm the guarantees of the implementation before using IDs as the sole source of business-event order.
v4: random-oriented, standardized UUID form v7: timestamp-oriented, standardized UUID form NanoID: configurable length with a compact alphabet
Compact IDs require a collision budget
NanoID trades a configurable alphabet and length for a shorter string. Reducing length reduces the possible identifier space. This tool offers validated URL-safe or alphanumeric presets, with bounds intended to avoid accidental huge output.
Keep uniqueness constraints and collision handling where your application needs them. An identifier is not an authorization token: a user must still be authorized to access the resource, even if its ID is difficult to guess. Use the separate secret generator when the value itself grants access.
Put a UUID into a JSON fixture
Export an identifier as JSON for an API fixture. This public example shows the shape, not a credential.
Input
UUID v4 · JSON export Example ID: f47ac10b-58cc-4372-a567-0e02b2c3d479
Expected output
[ "f47ac10b-58cc-4372-a567-0e02b2c3d479" ]
The third group starts with 4 and the fourth group carries the RFC variant. Fresh generated values differ. UUID v7 embeds creation time, while NanoID uses a configurable random alphabet; none replaces access control.
Keep the references close
Primary documentation supports the technical details above. Check it alongside the behavior of your own runtime and deployment.
Open UUIDs & NanoIDs →