Scrivio Interview library
DesignAdvanced6 min read · updated 12 November 2026

Choose an identifier strategy for a multi-region platform where records are created in several regions, merged into analytics, and exposed in public URLs.

For records created in several regions, we would generate ids in the application as time-ordered UUIDs (version 7) or a similar scheme, because they need no coordination between regions, never collide when data is merged into analytics, and keep index locality much better than random UUIDs. We would not expose internal ids in public URLs if they leak business volume; a separate public id, random or opaque, goes into URLs. We accept the 16-byte key size knowingly, and make the choice one standard across the platform so analytics joins stay consistent.

Why this question is asked

Identifier choices look like a detail until data from three regions lands in one warehouse and two different customers share id 1042, or a competitor reads our order volume from sequential numbers in URLs. A multi-region platform puts three demands on ids at once: they must be created independently, stay unique when merged, and be safe to show to the world. Interviewers ask this to see whether we weigh those needs together. In this answer, we will look at why regional sequences struggle, how time-ordered UUIDs solve the coordination problem, why public ids should be separate, what UUIDs cost in storage, and why one standard matters.

1The Requirements Behind the Question

Records are created in several regions, for example eu-west, us-east and ap-south, each with its own database so that writes stay local and fast. Their data is merged into a central analytics store. And some records, such as orders or shared documents, appear in public URLs. So an id must be generated without asking another region, must stay unique across all regions forever, and must not reveal anything we do not want to reveal.

2Why Regional Sequences Are Fragile

A database sequence is unique only within its database. Two regions with their own sequences will both produce 1, 2, 3, and the analytics merge collides immediately. There are workarounds. We can give each region a disjoint range (eu from 1 to 1 billion, us from 1 billion to 2 billion), start each at a different offset and step by the number of regions, or prefix ids with a region number.

All of them work on day one and become fragile later. Ranges run out at different speeds, and someone must notice. Adding a fourth region changes the step or needs a new range. Restoring a region's database from backup into another region, or moving a customer between regions, breaks the assumption that the region in the id is where the record lives. Every rule is a piece of coordination that people must remember, and the cost of forgetting is silent duplicates.

3Time-Ordered UUIDs: No Coordination, Good Locality

A UUID is a 128-bit value generated with enough randomness that two generators anywhere will practically never produce the same one. So each service in each region creates ids locally, with no round trip and no shared state, and the analytics merge simply works.

The problem with classic random version 4 UUIDs is index locality. A B-tree index keeps keys in sorted order, and random keys land on random pages, so inserts touch the whole index, cause page splits and push useful pages out of memory. A version 7 UUID begins with a 48-bit millisecond timestamp followed by random bits, so ids created close in time are close in the index and inserts append near the right edge, much like a sequence.

Java
@Entity
class Order {
@Id UUID id = UuidV7.next(); // our small generator, or Hibernate's time-based @UuidGenerator style; check your version
@Column(unique = true, nullable = false) String publicId = PublicIds.random(12); // "k7Qm2xPa9TzR"
}
// 0192f3a1-7c4e-7b21-9a6d-3e5f0c8d2b17 created 10:00:00.001
// 0192f3a1-7c4f-7d02-8e11-a4b9c0f7e5a3 created 10:00:00.002 <- sorts right after the previous one
// PostgreSQL 18 also has a uuidv7() function if the database should generate them
Options for multi-region ids
OptionCoordinationMerge safeIndex localitySize
Sequence per regionnone, but collidesnogood8 bytes
Ranges or region prefixranges and rules to maintainyes, if rules holdgood8 bytes
Random UUID (v4)noneyespoor16 bytes
Time-ordered UUID (v7)noneyesgood16 bytes
Snowflake-style 64-bitunique node numbersyesgood8 bytes

Notice that the leading digits of the two ids are almost the same. That shared prefix is what keeps inserts local in the index. A 64-bit alternative in the same spirit is a Snowflake-style id, a timestamp plus a node number plus a counter, which keeps 8-byte keys but brings back a little coordination: every node needs a unique number.

4Keep Public Ids Separate

Even a perfect internal id may not belong in a URL. Sequential numbers leak volume: if a customer sees order 50,200 today and 51,700 next week, they know we take about 1,500 orders a week. They also invite enumeration, trying /orders/50201 to see what happens. A UUIDv7 leaks less, but its timestamp still reveals when a record was created.

So for anything public we add a separate public id: a random, opaque string generated once, stored with a unique constraint and used only at the edges, in URLs and APIs. Internal joins and foreign keys keep using the internal id. Because the two are separate, either can change later without breaking the other, for example rotating a leaked share link without touching any foreign key.

5The Storage Cost of UUIDs

A UUID stored in PostgreSQL's native uuid type takes 16 bytes, twice a bigint. The cost is not only in the primary key: every foreign key column and every index that includes it doubles too. For a table of 2 billion rows with the key in three indexes and two referencing tables, that is tens of gigabytes more storage and more memory needed to keep indexes cached. We must store UUIDs in a native binary type, never as a 36-character string, which would cost more than twice as much again.

For most platforms that cost is acceptable for the coordination it removes. If a few very large tables are dominated by key size, a Snowflake-style 64-bit id is the compromise we would consider for those.

6One Standard for the Whole Platform

Finally, the decision should be the same everywhere. If orders use UUIDv7, customers use regional sequences and payments use strings, every analytics join needs conversion rules, and every new service asks the same question again. We would write the standard down in an architecture decision record: UUIDv7 internal ids generated in the application, stored as native uuid, a separate public id for anything exposed, and a shared library that generates both, so every team does it the same way.

7Follow-up questions

Why not let the database generate the UUIDs?

It works, and PostgreSQL 18 can generate version 7 UUIDs itself. Generating in the application has two advantages: the id is known before the insert, so Hibernate can batch and we can publish events that carry the id, and the generator is the same regardless of which database a region uses.

Does the timestamp in a UUIDv7 create a privacy risk?

It reveals creation time to the millisecond. For internal ids that is fine, and for public use we have the separate opaque public id, so the timestamp never reaches users.

What if two regions create the same business entity, such as the same customer?

Unique ids do not solve that; it is a business identity question. We would decide which region owns a customer, or match on a natural key such as an email at merge time, and record the mapping, rather than expecting the id to detect duplicates.

8Conclusion

In this answer, we saw that regional sequences need ranges or prefixes that become fragile as regions change, while application-generated time-ordered UUIDs need no coordination, stay unique in analytics and keep inserts local in the index. We keep internal ids out of public URLs with a separate opaque public id, accept the 16-byte storage cost knowingly or use a 64-bit Snowflake-style id for the largest tables, and write one standard for the platform so joins stay consistent.

What to say in the interviewAbout 90 seconds aloud

Open with

I would start from the three requirements: ids are created independently in several regions, they must stay unique when merged into analytics, and some of them show up in public URLs.

Then, if they want more

Per-region database sequences fail the second requirement unless we coordinate with ranges or region prefixes, and those schemes are fragile: ranges run out, adding a region changes the rules, and moving data between regions breaks the meaning of the prefix. So I would generate ids in the application as time-ordered UUIDs, version 7.

They need no coordination at all, they are unique across regions, and because they start with a millisecond timestamp, new ids sort near each other, which keeps B-tree inserts local instead of scattering them like random version 4 UUIDs.

I would store them in the native uuid type and be honest about the cost: 16 bytes instead of 8 in every key and index, which matters for very large tables, where a 64-bit Snowflake-style id is the alternative.

For public URLs I would not expose internal ids at all, because sequential ids leak business volume and invite enumeration, and even UUIDv7 leaks creation time. A separate random public id with a unique constraint goes into URLs and APIs.

And I would make this one platform standard, written as an architecture decision with a shared library, so analytics joins are consistent across all services.

About this answer

Last updated
12 November 2026
Versions it names
PostgreSQL 18
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.
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 "Choose an identifier strategy for a multi-region platform where records are created in...": https://scrivio-interview-library.netlify.app/databases/jpa-fundamentals/f9da98599c/