Skip to content
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

Monotonicity in UUIDv7 #148

Closed
bensie opened this issue Jan 2, 2024 · 2 comments
Closed

Monotonicity in UUIDv7 #148

bensie opened this issue Jan 2, 2024 · 2 comments

Comments

@bensie
Copy link

bensie commented Jan 2, 2024

UUIDv7 was shipped in #139 (and is included in v1.5.0), but appears to have skipped the part of the spec that expects monotonic ordering for batch creation.

Additionally, care MUST be taken to ensure UUIDs generated in batches are also monotonic. That is, if one-thousand UUIDs are generated for the same timestamp; there is sufficient logic for organizing the creation order of those one-thousand UUIDs. For batch UUID creation implementions MAY utilize a monotonic counter which SHOULD increment for each UUID created during a given timestamp.

In the following code sample, the output is always:

➜  go run main.go
uuidv7 false
package main

import (
	"fmt"

	"github.com/google/uuid"
	"golang.org/x/exp/constraints"
)

func main() {
	length := 10000

	uuids := make([]string, length)
	for i := 0; i < length; i++ {
		uuidString, _ := uuid.NewV7()
		uuids[i] = uuidString.String()
	}

	fmt.Println("uuidv7", isSorted(uuids))
}

func isSorted[T constraints.Ordered](collection []T) bool {
	for i := 1; i < len(collection); i++ {
		if collection[i-1] > collection[i] {
			return false
		}
	}

	return true
}

Can this implementation be modified to support monotonically increasing UUIDs?

Thank you!

@sergeyprokhorenko
Copy link

sergeyprokhorenko commented Jan 28, 2024

I advise you to take the following implementations as an example:
Rust
PostgreSQL
It is these implementations, created with the participation of the most important RFC contributors (LiosK and Sergey Prokhorenko), that are closest to understanding the RFC.

@bensie
Copy link
Author

bensie commented Jan 29, 2024

Closed by #150

@bensie bensie closed this as completed Jan 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants