UUID Generators: When and How to Use Them
UUIDs (Universally Unique Identifiers) are 128-bit values used to identify records, resources, and entities across distributed systems. They are everywhere in modern development — database primary keys, API resource identifiers, file names, and distributed system correlation IDs. Here is everything you need to know about choosing and generating UUIDs.
UUID Versions Explained
UUID v1 is generated from the current timestamp and the machine MAC address. It is sortable by creation time but exposes the machine identity, which is a privacy concern. Rarely used in modern applications.
UUID v4 is purely random — 122 random bits with 6 bits reserved for version and variant identifiers. This is the most commonly used version. The probability of collision is astronomically low — you would need to generate 2.71 quintillion v4 UUIDs to have a 50% chance of one collision. Our UUID Generator creates v4 UUIDs using the Web Crypto API for cryptographic randomness.
UUID v7 is the newest and increasingly recommended version. It encodes a Unix timestamp in the first 48 bits, followed by random bits. This makes v7 UUIDs sortable by creation time (like v1) while being random and privacy-preserving (like v4). Database performance is significantly better because sequential IDs avoid random B-tree page splits.
When to Use UUIDs
UUIDs are the right choice when you need globally unique identifiers without coordination between systems. Distributed databases where multiple nodes create records independently. Microservices where each service generates its own IDs. Public-facing API resource identifiers where sequential IDs would expose business metrics. Merge operations where records from different sources must coexist without ID conflicts.
When NOT to Use UUIDs
UUIDs are not always the best choice. For single-database applications, auto-incrementing integers are simpler, smaller (4-8 bytes vs 16 bytes), and faster for index operations. For human-facing identifiers, UUIDs are unfriendly — use short codes (like YouTube video IDs) or slugs instead. For high-performance scenarios with millions of inserts per second, UUID v4 random distribution can cause index fragmentation — use UUID v7 or ULID instead.
UUID Tools
Our UUID Generator creates v4 UUIDs in your browser with bulk generation (up to 1,000 at once), format options (standard, uppercase, no hyphens), and validation of existing UUIDs with version detection. For command-line generation: uuidgen on macOS/Linux, or node -e "console.log(crypto.randomUUID())" using Node.js. In code, use the uuid npm package or your language standard library.
Database Considerations
Storing UUIDs as CHAR(36) wastes space and is slow for indexing. Store them as BINARY(16) in MySQL or UUID native type in PostgreSQL. If using Prisma, the @default(cuid()) generates CUIDs which are shorter, URL-safe, and sortable — a pragmatic alternative to UUIDs for many applications. For new projects, consider UUID v7 or ULID (Universally Unique Lexicographically Sortable Identifier) for the best combination of uniqueness, sortability, and database performance.
CUID vs UUID vs ULID
CUIDs are shorter, URL-safe, and collision-resistant but not standardized. UUIDs are the industry standard with wide tooling support. ULIDs provide Crockford Base32 encoding (26 characters, case-insensitive, URL-safe) with timestamp-based sorting. For database primary keys in new projects, UUID v7 or ULID is the recommended choice in 2026. For backward compatibility with existing systems, UUID v4 remains the safe default.
Related Posts
Sponsor Our Newsletter
Reach thousands of developers who are actively evaluating AI tools, MCP servers, and dev infrastructure. Our weekly newsletter goes to engaged technical decision-makers.
All sponsored content is clearly labeled per our editorial policy.