PRACTICAL GUIDE

Use Random UUIDs as Identifiers

Generate one or a batch of random version 4 UUIDs using your browser’s cryptographic random source.

Pick an identifier for the job

Version 4 UUIDs are useful when separate clients need to create identifiers without coordinating a sequence. They are not chronological. If insertion order is important, choose an identifier design suited to your database and application.

Check the format

A standard hyphenated UUID contains 32 hexadecimal digits and four hyphens. The version digit in this generator is 4. Check whether the consuming API expects that format, a compact representation or a native database UUID type.

Keep database constraints

Random generation makes accidental collisions extremely unlikely, but it does not replace a uniqueness constraint. Let your database enforce the rule and handle a rejected insert appropriately. Generate fresh identifiers for independent records.

Separate identity from access

A hard-to-guess record identifier is not an authorization check. Your application still needs to decide who may read or modify each record. Do not treat an identifier as a password or a replacement for an access-control policy.

Put it into practice