5 min read
2026-02-10
UUID v4 is a universal choice. UUID v7 - if you need to sort by time. UUID v5 - for deterministic generation.
In MySQL, use `BINARY(16)` instead of `CHAR(36)` - this saves 55% of space and speeds up indexes.
Unlike v4, the v7 UUID contains a timestamp, which allows for sequential insertion into the B-tree index.
UUID is too long for user interfaces - consider NanoID or short hashes.
Don't rely on UUID for authorization - v4 is random, but not a cryptographic token.
Before using, check the format with a regular expression: `^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$`.
See also: Password generator, Slug generator