Quick revision
The short answer
I would start from the problems the rule is meant to solve, such as generating ids across services, merging data, hiding enumerable ids and offline creation, and notice that a public UUID column solves most of them without touching internal keys. So the rule would apply to new tables, with shared UUIDv7 libraries and storage formats per database, while existing large bigint tables migrate only where a real benefit outweighs the rewrite, and documented exceptions remain for cases where bigint is cheaper.
What to remember
In this answer, we saw how to turn a blanket 'all primary keys are UUIDv7' proposal into a useful standard: name the problems it should solve, separate internal clustered keys from public identifiers, apply UUIDv7 to new tables while migrating existing large tables only for a concrete benefit, provide shared libraries and per-database storage formats, and back the defaults and exceptions with benchmarks on realistic data.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
I would start from the problems the rule is meant to solve, such as generating ids across services, merging data, hiding enumerable ids and offline creation, and notice that a public UUID column solves most of them without touching internal keys. So the rule would apply to new tables, with shared UUIDv7 libraries and storage formats per database, while existing large bigint tables migrate only where a real benefit outweighs the rewrite, and documented exceptions remain for cases where bigint is cheaper.
Background to this question
Company-wide standards are where good ideas become expensive. 'All primary keys are UUIDv7' sounds tidy, but on a 2 billion row MySQL table it means rewriting the table, every foreign key, caches and the events other teams consume. A senior engineer is expected to find the goal behind a rule, write a standard that achieves it, and roll it out without forcing pointless migrations. In this answer, we will clarify the problems, separate internal and public ids, estimate the migration cost, write the standard with its tooling, and decide on exceptions using measurements.
1Start With the Problems, Not the Rule
Before agreeing or disagreeing, we ask the teams pushing the rule what went wrong. Usually it is one of four things. Services want to create ids before they talk to the database, for example to publish an event and write a row with the same id. Data from several databases has to be merged and the bigint ranges collide. Public URLs like /invoices/10432 let someone guess other invoices or estimate our volume. Or mobile clients create records offline and sync later.
Each of these is real, but they need different things. Only the first and last really need ids created outside the database. The enumeration problem needs ids that are hard to guess only where they are exposed. Merging needs globally unique ids only where data crosses databases. Writing the problems down turns an argument about taste into a decision with criteria.
2Separate Internal Keys From Public Identifiers
An internal key is what the database uses for clustering, joins and foreign keys. A public identifier is what leaves the service: in URLs, API responses and events. They do not have to be the same column. A table can keep id bigint as its clustered primary key and add public_id as a UUIDv7 column with a unique index.
This solves enumeration and cross-service references immediately, for a cost of one extra 16-byte column and index per table. The large MySQL tables keep their compact clustered keys, which matters a lot in InnoDB, where every secondary index repeats the primary key. So the first part of the standard is: every entity exposed outside its service has a UUID public identifier. That part can be adopted everywhere quickly.
| Problem | Public UUID column | UUIDv7 primary key |
|---|---|---|
| Hide enumerable ids in URLs | yes | yes |
| Reference rows across services and events | yes | yes |
| Create ids before the database insert | yes, if generated in code | yes |
| Merge tables from several databases | partly, internal keys still collide | yes |
| Compact clustered key and joins | yes, keeps bigint | no, 16 bytes everywhere |
| Cost on existing large tables | add column and backfill | rewrite table and all foreign keys |
3What Changing an Existing Key Really Costs
Changing the primary key of a large existing table is far more than an ALTER. The table and all its secondary indexes are rewritten, which on MySQL means an online schema change running for hours or days. Every child table's foreign key column changes type and gets rewritten too. Caches keyed by the old id, search indexes, data warehouse tables, and events already published with numeric ids all have to be translated. Other teams' consumers may store the old ids.
For a table with billions of rows that work can take a team a quarter, with real risk, and the benefit might only be consistency. So the second part of the standard is: new tables use UUIDv7 primary keys by default, and existing tables migrate only when one of the listed problems actually hurts them and the cost has been estimated.
4Making It Easy to Do the Right Thing
A standard that each team implements by hand will drift. Some will generate version 4, some will store text, some will get the byte order wrong in MySQL. So the platform team provides a small, well-tested UUIDv7 library for each language we use, for example Java, Go and TypeScript, with monotonic generation within a millisecond, plus Hibernate and JSON mappings for Java.
We also decide storage per database: the native uuid type in PostgreSQL (with uuidv7() available from version 18, check your version), BINARY(16) in MySQL with helper functions for conversion, and the canonical string form in APIs and events. Migration linting checks that new id columns use these types, and a template service shows the whole pattern working.
5Benchmarks and Documented Exceptions
Some workloads are genuinely cheaper with bigint. A high-volume append-only table, such as a metrics or audit log with 50,000 inserts per second and several secondary indexes, pays for every extra byte in every index and in replication. So before making UUIDv7 the default, we benchmark it on realistic data in each database we use, comparing insert throughput, index size and join cost against bigint.
Where the numbers show a real penalty, the standard lists the exception explicitly: append-only internal tables that are never exposed may use bigint identity keys. Exceptions are recorded in the service's architecture notes, so a reviewer can see why a table differs instead of assuming someone forgot the rule.
- Is this a new table?YesDefault to a UUIDv7 primary keyNoKeep the existing key for now
- Does an existing table expose ids outside the service?YesAdd a public UUIDv7 columnNoNo change needed
- Does a listed problem hurt it, with cost estimated?YesPlan a migration with owners and datesNoLeave the key as it is
- Is it a high-volume internal append-only table?YesAllow bigint as a documented exceptionNoFollow the default
4 steps in order. Play them, or step through them one at a time.
6Rolling It Out
We publish the standard as a short written decision with the reasoning, the defaults and the exceptions, discuss it with the teams that own the largest tables, and give it a start date for new tables. Then we track adoption with the migration linter and review migration requests individually. After six months, we review incidents and benchmarks to see whether the rule solved the original problems. A standard that came from a debate is only settled when the people who opposed it can see their concerns written into it.
7Follow-up questions
What if a team insists that every table must be identical for simplicity?
Consistency has value, but the cost of rewriting large tables is concrete and the benefit is mostly aesthetic. I would show the cost estimate and offer consistency where it matters to other teams, which is the public identifier in APIs and events. Inside a service, the key type is an implementation detail.
How do we migrate a table that really needs a new key?
Add the UUID column, backfill it in batches, make new writes fill it, switch readers and child tables to it one by one, and only then change the primary key in a planned rewrite. Each step is reversible until the last one.
Should events carry the internal key at all?
Preferably not. Events are a public contract, so they should carry the public UUID. Then internal keys can change later without breaking consumers.
8Conclusion
In this answer, we saw how to turn a blanket 'all primary keys are UUIDv7' proposal into a useful standard: name the problems it should solve, separate internal clustered keys from public identifiers, apply UUIDv7 to new tables while migrating existing large tables only for a concrete benefit, provide shared libraries and per-database storage formats, and back the defaults and exceptions with benchmarks on realistic data.
Open with
I would start by asking what problem the rule is solving. Usually it is ids created across services, merging data, avoiding guessable ids in URLs, or offline creation.
Then, if they want more
Then I would point out that internal keys and public identifiers are different jobs. A public UUIDv7 column with a unique index solves enumeration and cross-service references without rewriting tables, and that matters for MySQL, where the clustered key is repeated in every secondary index.
Changing the primary key of a large existing table means rewriting it, changing every foreign key, and translating caches, events and warehouse data, so I would apply UUIDv7 as the default for new tables and migrate existing ones only when a real problem justifies an estimated cost.
To make the standard work, the platform team would ship a tested UUIDv7 library per language and decide storage per database: native uuid in PostgreSQL, BINARY(16) in MySQL, and the string form in APIs. I would benchmark on realistic data and document exceptions, such as a high-volume internal append-only table where bigint stays cheaper.
Then I would publish it as a written decision, lint new migrations, and review after six months whether it actually solved the original problems.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- PostgreSQL documentation, MySQL reference manual
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Your organisation is debating a company-wide rule: 'all primary keys are UUIDv7'. Some...": https://scrivio-interview-library.netlify.app/databases/data-modeling/ce83e7397e/