GopherCon 2024 was held in Chicago, Illinois from July 7–10, 2024. The annual Go community conference brought together engineers from across the ecosystem for talks on language internals, libraries, and production patterns.
google/uuid 1.6 — UUID v7 Lands in the Standard Go Library
The most significant UUID-related announcement in the Go ecosystem leading up to GopherCon 2024 was the release of google/uuid version 1.6, which added uuid.NewV7(). This made UUID v7 generation a one-line change for any Go project already depending on the package — which covers the vast majority of Go services using UUIDs.
Sessions at GopherCon 2024 explored the practical implications. The google/uuid package is the de facto standard for UUID generation in Go, used directly or transitively by GORM, pgx, go-chi, and many other popular libraries. With v7 support in the package, the community upgrade path became straightforward.
Generating UUID v7 in Go
The new API is minimal and idiomatic:
import "github.com/google/uuid"
id, err := uuid.NewV7()
if err != nil {
// handle error
}
fmt.Println(id.String()) // e.g. "018fbe3a-4c5d-7b12-8abc-0123456789ab"
The version nibble is 7, and the variant bits conform to RFC 9562. The timestamp uses Unix milliseconds in the high 48 bits; the remaining 74 bits are random.
GORM Integration
GORM users can switch to UUID v7 primary keys with a small hook change. The pattern shown at GopherCon 2024:
type User struct {
ID uuid.UUID `gorm:"type:uuid;primary_key"`
CreatedAt time.Time
Name string
}
func (u *User) BeforeCreate(tx *gorm.DB) error {
id, err := uuid.NewV7()
if err != nil {
return err
}
u.ID = id
return nil
}
This pattern works with PostgreSQL, MySQL, and SQLite backends. The uuid column type stores the value as a 16-byte binary in MySQL (using BINARY(16)) or as a native uuid type in PostgreSQL.
pgx and Direct PostgreSQL Integration
For services using pgx directly, UUID v7 values from google/uuid serialize to PostgreSQL’s native uuid type without any additional configuration. The pgx driver handles the type mapping automatically.
Sessions noted that because UUID v7 values are monotonically increasing within each millisecond window, PostgreSQL B-tree indexes on UUID v7 primary keys behave similarly to BIGSERIAL indexes in terms of insert locality — dramatically reducing page splits under high insert rates.
Choosing v7 Over v4 in Go Services
Talks summarized the decision criteria:
| Scenario | Recommendation |
|---|---|
| New service, PostgreSQL/MySQL primary key | UUID v7 — better index performance |
| Existing service with UUID v4 primary keys | Keep v4 unless migrating schema; use v7 for new tables |
| External API identifiers exposed to clients | Either; v7 leaks creation timestamp — consider if acceptable |
| Distributed trace/correlation IDs | UUID v7 — enables temporal sorting across services |
| Short-lived in-memory identifiers | Either; performance difference is negligible |
Related Go and UUID Resources
- google/uuid package documentation — official Go package with NewV7() function
- GORM documentation — ORM for Go with UUID support
- pgx driver — PostgreSQL driver with native uuid type support
- RFC 9562 — UUID v7 specification
Frequently asked questions
Have there been conference talks about UUID v7?
Yes. UUID v7 has been covered at PGConf.EU, KubeCon, DjangoCon, and GopherCon since RFC 9562 was published in 2024. Talks have focused on the B-tree index performance improvement over UUID v4, the PostgreSQL 18 native uuidv7() function, and migration patterns for existing schemas.
How do I generate a UUID in Go?
Install github.com/google/uuid (go get github.com/google/uuid), then call uuid.New() for a random v4 or uuid.NewV7() for a time-ordered v7. Both return a uuid.UUID value — a [16]byte array with String(), JSON marshalling and database driver support built in.
Do UUIDs hurt database index performance?
UUID v4 does — its randomness causes every insert to land at a different leaf page, leading to page splits and poor cache locality. UUID v7 embeds a millisecond timestamp so consecutive inserts cluster together, behaving like an auto-increment integer for B-tree purposes.
How do I generate a UUID v7 in Go?
Use the google/uuid package version 1.6 or later: id, err := uuid.NewV7(). The function returns a uuid.UUID value and an error (which is nil under normal conditions). No additional configuration is needed — the library handles timestamp generation and random bit filling automatically.
Can I use UUID v7 with GORM in Go?
Yes. Define your model's primary key as uuid.UUID and set the BeforeCreate hook to call uuid.NewV7(). Alternatively, set a default directly in the struct tag. GORM treats uuid.UUID as a native type when used with PostgreSQL or MySQL drivers that support the uuid column type.