UUIDv7, modern alternative to auto increment and UUIDv4
Auto increment
Pros
Faster indexing and smaller index using minimal space
Cons
Reveals incremental number
Without access control, malicious users can navigate one by one by typing in url or manipulating request
Chance of collision when two servers insert at exact same millisecond
UUIDv4
Pros
Frontend and backend can generate UUID
Cannot predict next id
Astronomically low chance of collision
Cons
Slower indexing and larger index
Slower queries compared to auto increment
Slightly more difficult debugging due to having to copy paste long string(s)
UUIDv7, the modern alternative
UUIDv7 is a time-ordered identifier composed of timestamp and random data.
Using 019f2c10-4593-79c0-a7ab-67844b6c8c93 as an example
| 019f2c10-4593 | -79c0a7ab-67844b6c8c93 |
|---|---|
| Based on timestamp | Unique and unpredictable |
Before using UUIDv7, check whether your frontend/backend language supports it natively or have to use a package.
While existing databases can support UUIDv7, newer versions like Postgres 18 released on Sep 2025 started supporting it natively by providing uuidv7().