UUIDs as Database Primary Keys

Description

Postgres allows the use of UUIDs as primary keys for database records. This is in contrast to the default of using auto-incrementing integers for primary keys.

Pros:

  • UUIDs do not reveal information about the referenced data (e.g. a record’s relative position in the database)
  • UUIDs provide uniqueness across multiple databases
  • It’s possible to embed arbitrary metadata in UUIDs

Cons:

  • Cumbersome to communicate between humans
  • Not the default behavior in Postgres and, as such, created asymmetry between tables
  • Do not work with Paper Trail out of the box
  • (Wunder-specific) Cumbersome data tree paths

Technology Status at Wunder

Retire.

In general, Wunder does not benefit from any of the pros associated with UUID PKs. We also suffer from some of the cons (namely: cumbersome communication). As such, we should avoid using UUIDs as PKs for new tables and, when appropriate, migrate existing UUID PKs to integers.