UUID v4 & v7 Generator (RFC 4122 & RFC 9562) – Complete Developer Guide & Reference

Generate cryptographically secure random UUID v4 and time-ordered UUID v7 unique identifiers.

Definition & Core Standards

A Universally Unique Identifier (UUID) is a 128-bit label standardized by RFC 4122 and RFC 9562 used to uniquely identify records across distributed computing systems without requiring centralized coordination.

Standard UUIDs are formatted as 32 hexadecimal digits displayed in five groups separated by hyphens (`8-4-4-4-12`), totaling 36 characters (e.g., `123e4567-e89b-12d3-a456-426614174000`). UUID v4 uses 122 bits of cryptographically secure pseudo-randomness. UUID v7, standardized in RFC 9562, combines a 48-bit Unix epoch millisecond timestamp with 74 bits of random data, making it naturally time-ordered and optimal for database primary key indexing.

Technical Deep Dive

Traditional auto-incrementing integer database IDs expose business metrics and risk sequential enumeration attacks. UUID v4 provides collision-free global uniqueness across distributed microservices. However, because UUID v4 values are random, using them as primary keys in B-tree database indexes causes severe index fragmentation. UUID v7 solves this by embedding millisecond timestamps at the start of the ID, maintaining sequential B-tree insertion locality while guaranteeing global uniqueness.

Key Production Use Cases

  • Generating primary keys for PostgreSQL, MySQL, and MongoDB database records.
  • Assigning unique transaction IDs and correlation IDs across microservice distributed tracing logs.
  • Creating secure session keys, API token identifiers, and file upload keys.
  • Generating idempotent request tokens for payment gateways and billing webhooks.

Engineering Best Practices

  • Prefer UUID v7 over UUID v4 for database primary keys to preserve B-tree index locality and write performance.
  • Always use cryptographically secure random number generators (`crypto.getRandomValues`) when generating UUIDs.
  • Store UUIDs as native 16-byte binary types in databases (e.g., PostgreSQL `UUID` type) to save disk space.

Implementation & Usage Steps

  1. Select UUID Version: Choose between random UUID v4 or time-ordered UUID v7.
  2. Set Quantity & Uppercase: Select batch quantity (e.g., 1 to 500 IDs) and letter case preferences.
  3. Generate Instantly: Click Generate to construct secure, collision-free UUID identifiers.
  4. Copy Batch: Copy generated UUIDs to clipboard or export as text file.

UUID v4 & UUID v7 Examples

// UUID v4 (Cryptographically Random)
f47ac10b-58cc-4372-a567-0e02b2c3d479

// UUID v7 (Time-Ordered Timestamp + Randomness)
019114f0-42ab-7210-9081-3f412ab34567

Frequently Asked Questions

What is the probability of a UUID v4 collision?

The probability of a collision among 2.3 billion UUID v4 values is approximately 1 in a billion, making collisions practically impossible in real-world software applications.

Why is UUID v7 better for database primary keys than UUID v4?

UUID v7 embeds a millisecond Unix timestamp at the beginning of the ID, ensuring new records are inserted sequentially at the end of database B-tree indexes rather than causing random page splits.

Is this UUID generator cryptographically secure?

Yes. OwnFormatters uses the browser's native `crypto.getRandomValues()` Web Crypto API to guarantee cryptographic entropy.