VIEW
← Back to Blogs

Moving from UUIDv4 to UUIDv7

Date: 19 March 2026  •  Topic: Database / Performance

When building scalable applications, we often reach for UUIDs over auto-incrementing integers. UUIDv4 has been the standard choice for a long time, generating purely random identifiers. However, this randomness introduces a significant problem: database indexing inefficiency.

The Problem with UUIDv4

Because UUIDv4 values are scattered and completely random, inserting them as primary keys in B-tree indexes (like MySQL's InnoDB uses) causes page splits and heavy disk fragmentation. This degrades write performance considerably as the table grows.

Enter UUIDv7: Time-Sorted and Sequential

UUIDv7 natively incorporates a UNIX timestamp (to the millisecond) into the beginning of the identifier. The remainder is filled with random bytes. This means that UUIDv7s are naturally sortable by creation time and are inserted sequentially.

Implementing in Laravel

Laravel provides great native support for generating UUIDs. You can easily use Laravel's default model traits like HasUuids to start generating v7 identifiers seamlessly.