What Is a UUID?
A UUID (Universally Unique Identifier) is a 128-bit label used to uniquely identify information in computer systems. The standard format displays UUIDs as 36 characters in a 8-4-4-4-12 pattern: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx. With 2^122 possible values (minus reserved bits), the probability of collision is astronomically small.
UUID Versions and When to Use Them
UUID v4 is the most common version, generated from random numbers. It is ideal for most applications including database primary keys, session identifiers, and API resource IDs. UUID v7 is a newer time-ordered version that incorporates timestamps, making it friendlier for database indexing. UUID v1 uses MAC address and timestamps — avoid it for privacy reasons as it exposes the generating machine's hardware address.
Why Use UUIDs Instead of Auto-Increment IDs?
UUIDs offer several advantages over auto-increment integers: they are globally unique across systems, making distributed databases and offline-first applications simpler. UUIDs cannot be enumerated (no one can guess the next ID). They work seamlessly in microservice architectures where each service generates its own identifiers without coordination.
How to Generate UUIDs Online
Online UUID generators create identifiers instantly using cryptographically secure random number generation. Most generators support multiple versions: v4 for random UUIDs, v7 for time-ordered UUIDs, and sometimes v1 and v5. The generator should process locally in your browser to ensure privacy — your data never reaches a server.
UUID Performance Considerations
UUID v4 keys can cause B-tree index fragmentation in databases because they are randomly ordered. UUID v7 solves this by encoding timestamps as the first bytes, producing roughly time-ordered values that index efficiently. If you need optimal database performance, prefer UUID v7 over v4 for primary keys.
UUID Best Practices
Store UUIDs as binary (16 bytes) rather than as strings (36 characters) to save space and improve query performance. Use the hypenated lowercase format for display and API responses. Never rely on UUIDs for security — they are unique but not secret. Always validate UUID formats on the server side.
