UUIDs have long been the gold standard for global identifiers in distributed systems. But for years, we’ve had to choose between randomness (UUIDv4) and ordering (UUIDv1) — with trade-offs either way.
Now, there's a new option: UUIDv7.
It’s timestamp-based. It’s sort-friendly. And it’s finally standardized in [RFC 9562 (2024)](https://datatracker.ietf.org/doc/rfc9562/).
Let’s explore how UUIDv7 works, why it matters, and how to use it today across multiple languages.
🚀 What Is UUIDv7?
UUIDv7 is designed to combine the best parts of UUIDv1 and UUIDv4:
- Time-sortable like UUIDv1
- Randomized and privacy-safe like UUIDv4
- Compact (128 bits) and compatible with existing UUID parsers
UUIDv7 Format (simplified):
- 48 bits: Unix timestamp in milliseconds
- 4 bits: Version (
0111
) - 74 bits: Random or entropy bits
Result:
- Chronologically sortable
- Globally unique (with 74+ bits of entropy)
- Safer than UUIDv1 (no MAC or clock leakage)
🧠 Why UUIDv7 Matters
Feature | UUIDv4 | UUIDv1 | UUIDv7 |
---|---|---|---|
Random | ✅ | ❌ (time/MAC) | ✅ (74+ bits) |
Sortable | ❌ | ✅ | ✅ |
Traceable | ❌ | ⚠️ MAC leaks | ✅ Anonymized |
Standard-compliant | ✅ | ✅ | ✅ (RFC 9562) |
Ideal for | Auth tokens | Logs/events | Event IDs, DB PKs |
💻 Using UUIDv7 Across Languages
🔹 JavaScript (Node.js)
Use the uuidv7
package:
npm install uuidv7
import { v7 as uuidv7 } from 'uuidv7';
console.log(uuidv7());
🔹 Python
Install the uuid6
package:
pip install uuid6
from uuid6 import uuid7
print(uuid7())
Or use ulid
for a similar result with base32 encoding.
🔹 Go
Use github.com/oklog/ulid
(or UUIDv7-native lib):
import (
"fmt"
"time"
"github.com/oklog/ulid/v2"
"math/rand"
)
func main() {
entropy := ulid.Monotonic(rand.New(rand.NewSource(time.Now().UnixNano())), 0)
id := ulid.MustNew(ulid.Timestamp(time.Now()), entropy)
fmt.Println(id.String())
}
While ULID is not UUIDv7, it serves a similar function.
🔹 Rust
use uuid7::uuid7;
fn main() {
let id = uuid7();
println!("UUIDv7: {}", id);
}
Install via:
uuid7 = "0.7"
🧪 Ideal Use Cases for UUIDv7
- Primary keys in distributed SQL and NoSQL databases
- Event identifiers in Kafka, Pulsar, or SQS
- Log entries and trace IDs
- Time-series storage, with ordering benefits
- Systems that need to sort IDs by creation time
⚠️ Cautions and Considerations
- UUIDv7 is new — some libraries or DBs may not fully support it yet
- Be careful with time accuracy (ensure millisecond precision)
- If you need base32 or lexicographic sortability, consider ULID
🧰 Implementation Tips
- Use a library — don't roll your own bit manipulation unless you know the spec
- Store UUIDv7 in
UUID
orBINARY(16)
columns — they're still 128-bit - Index by UUIDv7 for better locality in writes (vs UUIDv4)
Final Thoughts
UUIDv7 gives us the ordering of UUIDv1, the safety of UUIDv4, and a standardized format that works across modern systems.
It’s not just an evolution — it’s a solution to long-standing trade-offs in distributed ID generation.
🔧 If you’re building modern APIs, event systems, or scalable databases — the future is UUIDv7.