-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
base: main
Are you sure you want to change the base?
Switch UUIDs to UUIDv7 #4666
Conversation
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>
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()
}
}
|
@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): 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. |
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