UUID Use Case
UUID Surrogate Key
A surrogate key has no business meaning. A UUID surrogate shields internal data and stays stable when the 'real' identifier changes.
OpaqueStableDecouples schema
Generated locally with the Web Crypto API — nothing leaves your browser.
What Is UUID Surrogate Key?
- Natural keys (email, username) can change or leak PII. A surrogate UUID is stable and meaningless, so renaming a user never cascades through foreign keys.
- Keep the natural attribute unique with a separate
UNIQUEconstraint; the UUID remains the internal pointer.
How to generate
- Make the UUID the primary key.
- Add UNIQUE on the natural attribute (email, slug).
- Never expose the natural key in URLs if it is sensitive.
Use Cases
- User accounts keyed by id, uniquely emailed.
- Documents addressed by opaque id, titled by slug.
- API resources referenced by id, filtered by name.
Code Examples
PostgreSQL
CREATE TABLE users (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
email TEXT UNIQUE NOT NULL
);Frequently Asked Questions
Surrogate vs natural key?
Surrogate (UUID) is stable and PII-free; natural keys are human-meaningful but mutable. Use a surrogate PK and a unique constraint on the natural value.
Does a UUID surrogate hurt joins?
No more than any other key; the 16-byte width is negligible for typical table sizes.
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