Development

UUIDs for Developers: v4, v1, v5, and Database Keys

Generate collision-resistant IDs for APIs, databases, and distributed tracing without a central registry.

Mar 15, 2025·9 min read

Universally Unique Identifiers (UUIDs) give distributed systems collision-resistant IDs without a central allocator. Databases use them as primary keys, logs use them as correlation IDs, and APIs return them for resource references. Version 4 (random) is the default; versions 1 and 5 solve specific ordering and determinism needs.

UUID versions at a glance

Which version when
VersionHow it is builtBest for
v4Random 122 bitsGeneral-purpose IDs, API resources
v1Timestamp + MAC nodeTime-sortable IDs (privacy caveats)
v5SHA-1 of namespace + nameDeterministic IDs from stable inputs

UUIDs display as 32 hex digits in 8-4-4-4-12 groups. Some systems omit hyphens or wrap in braces—format is cosmetic; the 128-bit value is what matters.

UUIDs as database primary keys

Random v4 UUIDs fragment B-tree indexes in PostgreSQL and MySQL compared to sequential integers—trade randomness for insert locality. UUIDv7 (time-ordered) is gaining adoption for the best of both worlds; until then, weigh index performance against distributed ID generation.

Correlation IDs in APIs and logs

Assign each HTTP request a UUID correlation ID—pass it through microservices in headers (`X-Request-ID`) so support teams trace one user action across log lines. v4 randomness avoids coordination between servers.

Generate UUIDs instantly

The UUID Generator on XSular Tools creates v4, v1, and v5 identifiers in single or bulk mode (up to 1,000), with uppercase, brace, and hyphen-free formatting—all using crypto.randomUUID when available.

Try it now

UUID Generator — Free Online Unique ID Creator

Generate UUID v4, v1, and v5 identifiers — single or bulk up to 1,000 at once. Options for uppercase, braces, and hyphen-free formatting. Free browser-based UUID tool with session history — no signup, instant copy.

Open UUID Generator — Free Online Unique ID Creator

Related posts

Practical articles on writing, development, design, and productivity — each tied to a free XSular tool you can use right away.

Read article