uuid v7 or bigserial primary keys for a multi tenant app doing 50k rows a day Schema Design
Greenfield, Postgres, per-tenant isolation by org_id. Roughly 50k rows a day across the main tables. I keep reading that random uuids destroy index locality and that bigserials leak business information, which are both true and unhelpful at the same time. What do people actually run?
@migration_marek · 7mo ago · 2 replies
Do both.
bigserial(or identity) as the internal primary key that all your foreign keys use, plus apublic_idwith a unique index for URLs and the API. Joins stay narrow, external ids stay opaque, and you can change the external format later without touching your relationships.Prefix the public id by type —
inv_01hq...,org_01hq.... It costs nothing and the first time you are staring at a log line with a bare id and no idea what table it is from, you will understand.Reply
Report
@nadia_brill · 7mo ago
Went with this. Six months later the prefixes have saved me more debugging time than the choice of id type could ever have cost me.
Reply
Report