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?

How to generate

  1. Make the UUID the primary key.
  2. Add UNIQUE on the natural attribute (email, slug).
  3. Never expose the natural key in URLs if it is sensitive.

Use Cases

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