8000 Switch UUIDs to UUIDv7 by binaryfire · Pull Request #4666 · distribution/distribution · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Switch UUIDs to UUIDv7 #4666

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Switch UUIDs to UUIDv7 #4666

wants to merge 6 commits into from

Conversation

binaryfire
Copy link
@binaryfire binaryfire commented Jul 2, 2025

This PR switches UUIDs to UUIDv7. UUIDv7s are time ordered which makes them more efficient to store and query.
Here are some UUIDv4 vs UUIDv7 benchmarks with Postgres:

There's no downside to switching - these are still valid UUIDs so the change is fully backwards compatible. Being able to store things like events with UUIDv7 IDs will be beneficial to everyone.

Also, this makes it easier to change the UUID version in the future.

Closes: #4665

Signed-off-by: Raj Siva-Rajah <raj@zapzap.cloud>
Signed-off-by: Raj Siva-Rajah <raj@zapzap.cloud>
Signed-off-by: Raj Siva-Rajah <raj@zapzap.cloud>
Signed-off-by: Raj Siva-Rajah <raj@zapzap.cloud>
Signed-off-by: Raj Siva-Rajah <raj@zapzap.cloud>
Signed-off-by: Raj Siva-Rajah <raj@zapzap.cloud>
@thaJeztah
Copy link
Member
thaJeztah commented Jul 4, 2025

Do you have any information where querying these UUIDs would be relevant and changing would benefit performance? As far as I can see, these UUIDs are not stored anywhere, and only used for OTEL traces, and event IDs (which needed something unique).

Other uses are as part of tests, which just needed a sample value.

I think v7 is even (although very marginal) slower;

package main

import (
	"testing"

	"github.com/google/uuid"
)

func BenchmarkUUIDv4(b *testing.B) {
	b.ReportAllocs()
	for range b.N {
		uuid.NewString()
	}
}

func BenchmarkUUIDv7(b *testing.B) {
	b.ReportAllocs()
	for range b.N {
		uuid.Must(uuid.NewV7()).String()
	}
}
BenchmarkUUIDv4-10    	 3664420	       320.2 ns/op	      64 B/op	       2 allocs/op
BenchmarkUUIDv7-10    	 3247585	       370.2 ns/op	      64 B/op	       2 allocs/op

@binaryfire
Copy link
Author
binaryfire commented Jul 4, 2025

@thaJeztah Good point. The main thing I'm looking for is UUIDv7s for event ids. Reason being we store these in our Postgres db after processing incoming webhooks.

If you check out the links I shared above you'll see that insertion performance with Postgres is 30% better with UUIDv7s vs UUIDv4s (i.e. more or less as fast as bigints):
image

The only reason I replaced all occurences with the v7 logic was for consistency. But another option could be leaving everything as is and just using v7s for event IDs? Since they're probably the only thing people store in their own backends.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Performance improvement: Use UUIDv7 from google/uuid instead of UUIDv4
2 participants
0