UUIDs in a Database: The Real Tradeoffs
By toolbelt maintainers ·
Updated
Random UUIDs avoid collisions and wreck your index performance. The version you pick has consequences.
What is this tool?
A UUID is a 128-bit identifier, written as 32 hex digits with hyphens. Version 4 is random; versions 1, 6 and 7 embed a timestamp. That difference matters more than most people realise.
How it works
Version 4 uses a cryptographically secure random source in your browser, then sets the version and variant bits so the result is a well-formed v4 UUID.
Example
550e8400-e29b-41d4-a716-446655440000 Version 4, variant 1, generated from 122 random bits.
When to use it
Anywhere you need an identifier that will not collide across machines without coordination — primary keys, idempotency keys, correlation IDs in logs.
Optimization Tips
Random v4 keys as an index are expensive in some databases, because each insert lands in a random part of the B-tree. UUIDv7 is time-ordered and much friendlier to indexes. If you are choosing now, choose v7; if you already have v4 primary keys, that is fine at small scale and painful at large scale.
Frequently Asked Questions
Can two UUIDs collide?
Are these truly random?
Should I use them in URLs?
What about size?
Related tools
- Regex TesterTest regular expressions in real-time. See highlighted matches, named capture groups, exact character indexes, and test replacement strings with JavaScript flavors.
- Cron GeneratorExplain cron expressions in plain English and predict the next 5 run times. Validate syntax for Linux crontab or serverless schedulers before deploying jobs.
- Timestamp ConverterConvert Unix timestamps to human-readable dates and vice versa. Includes a live clock and automatically handles seconds or milliseconds for easy debugging.
- Timestamp BatchConvert a whole list of Unix timestamps or dates at once. The unit is detected per line, so mixed seconds and milliseconds are handled together.