Availability of UUID7
search cancel

Availability of UUID7

book

Article ID: 432324

calendar_today

Updated On:

Products

VMware Tanzu Spring Runtime

Issue/Introduction

UUIDv7 is a time-ordered, RFC 9562-standardized, 128-bit unique identifier based on a Unix Epoch timestamp (milliseconds) combined with random entropy. It offers improved sorting, indexing, and collision resistance over older versions, making it ideal for database primary keys. It enables naturally sorted, high-performance, and time-based queries

Resolution

The support for creating a Type 7 UUID (UUID7) is added in JDK 26.

Release notes:
https://jdk.java.net/26/release-notes

In JDK 26, you can generate UUIDv7 (time-ordered identifiers) using the new java.util.UUID.ofEpochMillis(long) method, which takes a 48-bit Unix timestamp to generate a RFC 9562-compliant UUID. This replaces external libraries for creating database-friendly, sortable, and monotonic keys.

import java.util.UUID;
import java.time.Instant;

// Generate a UUIDv7 based on the current time
UUID uuidV7 = UUID.ofEpochMillis(Instant.now().toEpochMilli());
System.out.println(uuidV7);