Generate Random UUID v4 for Database Records Online
Learn how UUID v4 identifiers work, when to use them for database primary keys, and how to generate them securely in your browser.
What is a UUID v4 and why use it for database records?
A UUID (Universally Unique Identifier) version 4 is a 128-bit identifier that looks like this: f47ac10b-58cc-4372-a567-0e02b2c3d479. The "v4" designation means it's generated using random numbers, making collisions statistically impossible—you'd need to generate about 2.71 quintillion UUIDs to have a 50% chance of a single duplicate.
Database developers use UUID v4 for primary keys when they need distributed systems to generate IDs independently without coordination. Unlike auto-incrementing integers (1, 2, 3...), UUIDs let multiple servers, microservices, or client applications create records simultaneously without risking duplicate IDs. This matters for distributed databases, offline-first mobile apps, and systems that merge data from multiple sources.
When should you use UUID v4 instead of auto-increment IDs?
Auto-incrementing integers work fine for simple applications with a single database server. They're compact (4-8 bytes vs 16 bytes for UUIDs) and create sequential indexes that databases handle efficiently.
Switch to UUID v4 when you have:
- Distributed systems: Multiple servers creating records independently
- Client-side record creation: Mobile apps or SPAs that need IDs before syncing to the server
- Data merging: Combining databases from different sources (franchises, acquisitions, multi-tenant systems)
- Security requirements: Auto-increment IDs expose your record count and make enumeration attacks trivial
- Public-facing IDs: URLs like
/users/12345reveal business metrics;/users/f47ac10b-58cc-4372-a567-0e02b2c3d479doesn't
The tradeoff is storage space and slightly slower index performance. A UUID primary key uses 16 bytes per record—in a 10 million row table, that's 160MB just for the primary key versus 40MB for integers. For most applications, this cost is negligible compared to the architectural flexibility.
How do I generate UUID v4 securely in the browser?
Modern browsers provide crypto.getRandomValues(), which uses the operating system's cryptographically secure random number generator. This is crucial—regular Math.random() is predictable and unsuitable for UUIDs that need to be truly unique.
The UUID Generator on JustUse.me uses this secure method and runs entirely in your browser. No data leaves your machine, which matters when generating IDs for sensitive systems or during development with production-like data.
You can also generate UUIDs programmatically:
JavaScript: