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?

How to generate

  1. Generate with crypto.randomUUID() or uuid.uuid4().
  2. Persist as UUID/BINARY(16), never CHAR(36) when you can avoid it.
  3. Default the column so callers do not need to supply it.

Use Cases

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