AG UUID

UUID Performance and Storage Tips

The factors that drive UUID performance when generating them in bulk and storing them in a database.

Generation performance

Generating UUIDs is very fast and rarely a bottleneck. In both the browser and on the server, a native API like crypto.randomUUID() is the fastest and safest choice. Even creating thousands at once imposes little overhead.

Storage size

Storing a UUID as a string (36 characters) takes more than twice the space of the 16-byte binary form. Using binary storage such as PostgreSQL's uuid type or MySQL's BINARY(16) improves both storage and index efficiency.

Index locality

Random v4 values get inserted scattered across the index, which can hurt write performance. For write-heavy tables, use a time-ordered v7 or a ULID so inserts land at the end of the index sequentially, reducing page splits.