UUID Use Case
UUID Database ID
A database ID generated as a UUID keeps application code free of a central ID allocator and plays well with replication.
App-side or SQLStore as 128-bitIndex-friendly
Generated locally with the Web Crypto API — nothing leaves your browser.
What Is UUID Database ID?
- You can generate the ID in your application (so the row is fully formed before insert) or in SQL via a default.
- Store it in the native
UUIDtype (PostgreSQL) orBINARY(16)rather than a 36-character string to save space and speed comparisons.
How to generate
- Generate with crypto.randomUUID() or uuid.uuid4().
- Persist as UUID/BINARY(16), never CHAR(36) when you can avoid it.
- Default the column so callers do not need to supply it.
Use Cases
- JPA / Hibernate entities with @GeneratedValue UUID.
- Django models using UUIDField.
- Dapper / raw SQL inserts from application code.
Code Examples
Python
import uuid
id = uuid.uuid4()PostgreSQL
SELECT gen_random_uuid();Frequently Asked Questions
Should the DB or the app generate the ID?
Either works. App-side generation lets you reference the ID before the insert; SQL defaults are simpler but hide the value until after insert.
CHAR(36) or BINARY(16)?
BINARY(16) halves storage versus a 36-char string and compares faster; convert the hex to bytes on write.
Related tools
UUID v1 GeneratorUUID v3 GeneratorUUID v4 GeneratorUUID v5 GeneratorUUID v6 GeneratorUUID v7 GeneratorUUID v8 GeneratorBulk UUID GeneratorShort UUID GeneratorUUID ValidatorUUID FormatterUUID as a Primary KeyUUID Database IDUUID Foreign KeyUUID Shard KeyUUID Partition KeyUUID in a Composite KeyUUID Surrogate KeyUUID API KeyUUID Session TokenUUID Access TokenUUID Refresh TokenUUID Idempotency KeyUUID Request IDUUID Correlation IDUUID Trace IDUUID CSRF TokenUUID NonceUUID FilenameUUID Object KeyUUID S3 KeyUUID Upload IDUUID Cache KeyUUID Blob NameUUID Temp FileUUID User IDUUID Account IDUUID Customer IDUUID Device IDUUID Tenant IDUUID Client IDUUID Anonymous IDUUID Member IDUUID Message IDUUID Event IDUUID Job IDUUID Task IDUUID Queue Message IDUUID Transaction IDUUID Order IDUUID Invoice IDUUID Payment IDUUID Reset TokenUUID Verification TokenUUID Invite CodeUUID API SecretUUID Share LinkUUID Magic LinkUUID Node IDUUID Worker IDUUID Lock IDUUID Cluster IDUUID Test DataUUID Seed DataUUID FixtureUUID Mock IDUUID Placeholder IDUUID Sample ID