Choosing Keys and Types
Pick BIGSERIAL vs UUID primary keys, decide between TEXT and VARCHAR(n), and choose the right type for every column.
Picking a Primary Key
Three real choices:
- BIGSERIAL — monotonically increasing 64-bit integer
- UUID — 128-bit globally unique
- Natural key — a real-world identifier (email, ISBN)
When BIGSERIAL Wins
Default choice for most apps:
- Small (8 bytes), fast index, cache-friendly
- Monotonic → recent data clusters at the end of the index
- Readable in URLs (e.g.
/posts/42)