Primary Key Design

UUID vs serial.

Overview

Primary key choice is one of the few database decisions that is hard to undo and easy to get wrong. BIGSERIAL is sequential and B-tree-friendly but coordinates through the database. UUIDv4 is globally unique but its randomness destroys B-tree locality on inserts and bloats indexes. UUIDv7 and ULID are time-sortable, keeping the locality benefit while still allowing client-side generation. Composite keys (tenant_id plus sequential) win for multi-tenant systems where isolation matters more than global ordering.

The approach

The practical approach is BIGSERIAL by default for single-database OLTP, UUIDv7 when clients need to generate IDs without coordination, composite keys for multi-tenant isolation, and an explicit per-table PK rationale committed to the schema documentation. The cost of a wrong PK is months of migration work; the cost of a deliberate choice is 30 minutes of thought.

Why this compounds

PK design compounds across the lifetime of the table. The right choice on day one prevents the painful migration on year three; the wrong choice multiplies as foreign keys and indexes accumulate. Teams that develop a vocabulary for PK choice early stop relitigating it on every new table.

PK design is a database discipline that pays off across years. Nova AI Ops integrates with database telemetry, surfaces index patterns, and supports the team’s schema design discipline.