UUID v4 vs UUID v7
UUID v4 is completely random and good for general identifiers. UUID v7 includes a timestamp prefix and sorts naturally by creation time, making it excellent as a database primary key.
UUID Format Options
- Hyphenated UUID: Standard 8-4-4-4-12 format.
- Uppercase GUID: Matches Microsoft system preferences.
- Braced GUID: Enclosed in curly braces {}.
- Quoted UUID list: Useful for SQL IN clauses.
- Bulk UUID generation: Create hundreds of IDs at once.
Database Use Cases
UUIDs are incredibly useful for distributed records, offline clients, APIs, queues, logs, and idempotency keys. They allow systems to generate IDs without waiting for a central database sequence, preventing ID collisions and hiding internal database row counts.
When to Use NIL UUID
The NIL UUID (00000000-0000-0000-0000-000000000000) is useful as a sentinel value for unset, empty, or default UUID fields where null is not permitted by the schema.
Frequently Asked Questions
1. What is the difference between UUID and GUID?
They are essentially the same thing. UUID (Universally Unique Identifier) is the standard term, while GUID (Globally Unique Identifier) is the term historically used by Microsoft.
2. Which UUID version should I use?
Use UUID v4 for purely random IDs, and UUID v7 when you need the IDs to be sortable by time (e.g., for database indexing).
3. Is UUID v7 better for databases?
Yes. Because UUID v7 is time-sorted, it reduces fragmentation in B-tree indexes compared to the completely random UUID v4.
4. Can two UUIDs collide?
The probability of a collision is so astronomically low that it is practically zero. You can generate billions of UUIDs per second for years without a collision.
5. Are generated UUIDs uploaded?
No. All UUIDs are securely generated using your browser's Web Crypto API and are never sent to our servers.
6. Can I generate UUIDs in bulk?
Yes, you can generate up to thousands of UUIDs at once and format them as lists.
7. What is a NIL UUID?
A NIL UUID is a special UUID where all bits are set to zero. It's often used as an empty or default value.