Quick revision
The short answer
Identifiers outlive almost every other decision because they spread into URLs, logs, partner systems and analytics, so changing them later is extremely costly. Auto-increment integers quietly assume there is one database, and mergers, sharding and multi-region designs break that assumption. The lessons are to prefer globally unique ids when the future is uncertain, to separate internal and external identifiers so each can change on its own, and to treat the id strategy as an architecture decision with a written record.
What to remember
In this answer, we saw that identifiers spread into URLs, logs, partner systems, analytics and documents, which makes changing them extremely costly. Auto-increment ids assume a single database, and mergers, sharding and multi-region designs break that assumption. The lessons are to prefer globally unique ids when the future is uncertain, to keep internal and external identifiers separate so each can change independently, and to treat the id strategy as an architecture decision with a written record that we revisit when the assumptions change.
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.
Identifiers outlive almost every other decision because they spread into URLs, logs, partner systems and analytics, so changing them later is extremely costly. Auto-increment integers quietly assume there is one database, and mergers, sharding and multi-region designs break that assumption. The lessons are to prefer globally unique ids when the future is uncertain, to separate internal and external identifiers so each can change on its own, and to treat the id strategy as an architecture decision with a written record.
Why this question is asked
Few people remember choosing auto-increment ids; it was the default when the first table was created. Years later, merging an acquired company's database and sharding our own both run into the same wall: id 1042 exists twice, and the number 1042 is printed on invoices, stored in partner systems and joined in a hundred reports. Interviewers ask this at leadership level to see whether we can turn a painful migration into lasting principles. In this answer, we will see why ids become so hard to change, which assumption auto-increment hides, what globally unique and separated ids buy us, and how to make the decision deliberately next time.
1Why Identifiers Become So Hard to Change
An id starts as a column in one table. Then it becomes a foreign key in other tables, appears in REST URLs, goes into log lines and traces, is sent to a payment provider and a CRM, lands in the data warehouse, is printed on invoices, and is quoted by customers on the phone. Each of these copies has its own owner and its own release schedule, and most of them were never designed to change.
So the cost of changing an id is not the cost of changing the column. It is the cost of finding and updating every system and document that stored a copy, often outside our control. That is why identifier decisions deserve more care than their simplicity suggests.
2The Hidden Assumption: One Database
An auto-increment column is unique only inside one table in one database. That is fine as long as the database is the only place that ever creates rows. A merger breaks it at once: both companies have customer 1042. Sharding breaks it too: if customers are split across eight shards by region, each shard's counter starts at 1 unless we carefully set offsets and steps, and every rebalancing has to respect them. Multi-region writes, offline clients that create records before syncing, and event-sourced systems that need the id before the insert all break it in the same way.
| Place | Who owns it | Cost of changing the id there |
|---|---|---|
| Foreign keys in our tables | our teams | a migration per table |
| Public URLs and bookmarks | customers | redirects kept for years |
| Logs and traces | operations | history becomes hard to search |
| Partner systems | other companies | negotiated, slow |
| Analytics warehouse | data team | rebuilt joins and reports |
| Invoices and documents | legal and finance | cannot be changed at all |
3Lesson One: Globally Unique Ids Leave Room for Change
If ids are globally unique from the start, structural changes become much easier. UUIDs, preferably time-ordered version 7 for index locality, or Snowflake-style 64-bit ids that combine a timestamp and a node number, can be created anywhere without coordination. Two merged databases do not collide, rows can move between shards without new ids, and new regions need no range planning.
This does not mean every system needs them on day one regardless of cost. A UUID doubles key size compared with a bigint. The lesson is to make the choice consciously: if there is any realistic chance of mergers, sharding or multiple writers, the extra bytes are cheap insurance compared with a renumbering project.
4Lesson Two: Separate Internal and External Identifiers
Much of the merger pain comes from one value doing two jobs. The internal id joins tables; the external id is what customers, partners and documents see. If they are the same value, an internal change forces an external one. If they are separate, we can renumber, shard or merge internally while customers keep their customer number, or issue new customer numbers while the internal keys stay the same.
In practice that means every exposed entity has an internal surrogate key and a separate public identifier with its own format and a unique constraint. Partner integrations and URLs use the public one; foreign keys use the internal one.
5Lesson Three: Write the Decision Down
The original choice was not wrong for a single application in one database. The failure was that nobody recorded it as a decision with its assumptions, so nobody noticed when the assumptions stopped being true. An architecture decision record, a short document with the context, the decision, the alternatives and the consequences, would have stated that the strategy assumes a single writer database and would need revisiting before sharding or acquisitions.
As a leader, I would add identifier strategy to the checklist of decisions that need a record and a review, alongside data ownership and API versioning, and I would revisit it whenever the company plans a merger, a new region or a sharding project. For the current migration, I would also use it as a teaching case: a short write-up of what the renumbering cost in time and money gives the next team a reason to take the decision seriously.
- Could rows be created in more than one place, ever?Yesuse globally unique idsNoa sequence may be fine
- Is the id shown outside the system?Yesadd a separate public idNointernal id only
- Record the decision and its assumptionsarchitecture decision record
- Revisit before mergers, sharding, new regions
4 steps in order. Play them, or step through them one at a time.
6Follow-up questions
Should we migrate everything to UUIDs now?
Not in one big project. We would introduce a global id alongside the existing integer keys for the entities that cross systems, use it in new integrations and events, and move foreign keys gradually where sharding or the merger requires it. The integer can remain as an internal detail where it does no harm.
How do we handle the acquired company's ids during the merger?
Assign new global ids to every merged record, keep the old ids as attributes with their source (for example acme:1042), publish a mapping from old to new, and support lookups by both during a transition period so partners and customers can move at their own pace.
Is it ever right to choose auto-increment ids today?
Yes, for internal tables with a single writer database and no exposure outside the system, where small keys and simple ordering matter. The point is to choose it knowing the assumption, and to record that assumption.
7Conclusion
In this answer, we saw that identifiers spread into URLs, logs, partner systems, analytics and documents, which makes changing them extremely costly. Auto-increment ids assume a single database, and mergers, sharding and multi-region designs break that assumption. The lessons are to prefer globally unique ids when the future is uncertain, to keep internal and external identifiers separate so each can change independently, and to treat the id strategy as an architecture decision with a written record that we revisit when the assumptions change.
Open with
The main lesson for me is that identifiers outlive almost everything else. An id starts as a column, but within a few years it is in foreign keys, public URLs, logs, partner systems, the data warehouse and on printed invoices, and most of those copies are owned by someone else.
Then, if they want more
So changing an id is never a schema change; it is a hunt across the whole company and its partners. Auto-increment integers carry a hidden assumption, that there is exactly one database creating rows.
That was true when the choice was made, and it stops being true the moment we merge with an acquired company that also has customer 1042, or shard our own data, or write in several regions. From this I take three practices.
First, when there is a realistic chance of mergers, sharding or several writers, use globally unique ids, like time-ordered UUIDs or Snowflake-style ids, and accept the extra key size as insurance. Second, separate internal and external identifiers: an internal surrogate for joins and a separate public number for customers and partners, so either can change without forcing the other.
Third, treat the id strategy as an architecture decision with a written record of its assumptions, and revisit it before any merger, sharding or region project. For the current situation, I would add global ids alongside the old ones and migrate gradually with a mapping from old to new.
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
- Spring Data JPA reference, Hibernate ORM documentation, Spring Framework reference, Transaction management
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 "Years after choosing auto-increment integer ids, your company must merge databases from...": https://scrivio-interview-library.netlify.app/databases/jpa-fundamentals/938d3f9123/