Quick revision
The short answer
Asynchronous replication cannot enforce a global unique constraint, because each region checks only its own copy and accepts the name before the other regions hear about it. To make usernames unique we either reserve names in one strongly consistent place (a home region or a consensus-backed store spanning regions), give each region ownership of a share of the namespace and route registrations to the owner, or accept duplicates and repair them afterwards. Registration is rare and can afford 100 to 200 ms more, so a strongly consistent global reservation is usually the right trade, while profile reads stay local.
What to remember
In this answer, we saw that asynchronous multi-region replication cannot enforce a unique username, because each region checks only its own rows before accepting. We compared a global reservation in a home region or consensus store, a partitioned namespace, and accept-and-repair, each paying in latency, availability or user trust. Because registration is rare and tolerates an extra 100 to 200 ms, a strongly consistent global reservation is usually right, with everything else, including profile reads, staying local.
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.
Asynchronous replication cannot enforce a global unique constraint, because each region checks only its own copy and accepts the name before the other regions hear about it. To make usernames unique we either reserve names in one strongly consistent place (a home region or a consensus-backed store spanning regions), give each region ownership of a share of the namespace and route registrations to the owner, or accept duplicates and repair them afterwards. Registration is rare and can afford 100 to 200 ms more, so a strongly consistent global reservation is usually the right trade, while profile reads stay local.
Why this question is asked
Uniqueness looks like the easiest rule in a database: one UNIQUE constraint and we are done. In an active-active, multi-region setup it becomes a real design decision, because the constraint is only as global as the data each region can see. Interviewers ask this to see whether we can explain why the bug happened and then price each fix in latency and availability. In this answer, we will recap why the local constraint did not help, look at three designs, put numbers on what each costs, and choose one.
1Why Two Regions Accepted the Same Name
Active-active means every region accepts writes. Asynchronous replication means a region commits a write locally and sends it to the other regions afterwards, typically within a few hundred milliseconds, sometimes much longer during network trouble.
Each region does have a unique index on username, but it can only check the rows it already has. User A registers alice in us-east at 10:00:00.300, and user B registers alice in eu-west at 10:00:00.900. Neither region has received the other's row yet, so both checks pass and both commits succeed. When replication delivers the rows, the regions now hold two accounts with the same name, and depending on the store either replication fails on the constraint or the duplicate quietly persists.
No amount of tuning fixes this. As long as each region decides alone, there is always a window in which both decide yes. To enforce uniqueness, the decision for a given name must be made in one place, or the duplicate must be detected and repaired later.
7 messages in order. Play them, or step through them one at a time.
2Option 1: A Global Reservation Store
The most direct fix is a reservation table that lives in exactly one logical place with strong consistency. That place can be the database in one home region, or a store that spans regions using consensus, such as Spanner, CockroachDB, or etcd for small data, where a write is committed only when a majority of replicas in different regions agree.
Registration first inserts the name into the reservation table, where a real unique constraint is enforced by a single authority, and only then creates the profile in the user's local region. If the insert fails, the name is taken.
The cost is a cross-region round trip on registration, for example 70 to 150 ms from Europe to a US home region, or a majority round trip for a consensus store. The availability cost is that registration fails or waits when the global store is unreachable from a region. Everything else, logins, profile reads and posts, stays local. The reservation should be written first and the profile second, with a cleanup job for reservations whose profile never got created.
3Option 2: Partition the Namespace
Instead of one central owner, each region owns a deterministic share of all possible names, for example by hashing the lowercased username and taking it modulo three. A registration is routed to the region that owns that name, which checks its local unique index; since only that region ever accepts that name, there is no race.
This spreads the load and means that a region outage blocks only a third of the namespace. But for a user in eu-west, two thirds of names are owned elsewhere, so most registrations still pay a cross-region round trip, and the owner region becomes a single point of failure for its share. It also makes adding or removing a region a migration of ownership, so it is more complex than option 1 for little gain unless registrations are extremely frequent.
4Option 3: Accept and Repair
The third option keeps registration fully local and fixes duplicates afterwards. Both regions accept alice. When replication delivers the second row, a detector notices the duplicate and applies a deterministic rule that every region computes the same way, for example the account with the earlier creation timestamp keeps the name, ties broken by user id. The other account is renamed to alice-2931 and the user is told to choose a new name.
This has the best latency and availability, but it is only acceptable when usernames can change and nothing has already used the name. If usernames appear in URLs, mentions or login, a renamed user may have shared a link that now points to someone else, which is a security and trust problem. Most social products would not accept that.
5Comparing the Costs and Choosing
The table puts the options side by side. The deciding fact is how often each path runs. A social app might see a few registrations per second but many thousands of profile reads per second. Adding 100 to 200 ms to a one-time registration is almost invisible to users, and making registration depend on a highly available global store is a small availability risk compared with the trust cost of duplicate names.
So the usual answer is option 1: a global reservation in a strongly consistent store, with profile data and reads staying in the user's region. To soften the availability cost, we choose a store that spans regions with consensus rather than a single home region, and we can show a friendly retry message if a region is cut off. Username changes go through the same reservation path.
| Option | Registration latency | When a region is lost | Main risk |
|---|---|---|---|
| Global reservation (home region) | +1 cross-region round trip | fails if home region is down | single home region |
| Global reservation (consensus store) | +1 majority round trip | works while a majority is up | operating the store |
| Partitioned namespace | +1 round trip for most names | a third of names blocked | complex rebalancing |
| Accept and repair | local only | always works | renaming users after the fact |
6Follow-up questions
What about checking availability as the user types?
That check can read a local, replicated copy of the reservation table, because it is only a hint. The authoritative step is the insert into the global store at submit time, which may still fail if someone took the name in the last second.
Could we use a distributed lock instead of a reservation table?
A lock per username would need the same strongly consistent store, plus lock expiry and fencing. Inserting into a table with a primary key in that store is simpler: the insert is the lock, and it never needs releasing.
Does this apply to email addresses as well?
Yes, for any value that must be unique across regions, such as emails or phone numbers on accounts. They go through the same reservation path, usually normalised (lowercased, trimmed) before the insert so variants cannot slip through.
7Conclusion
In this answer, we saw that asynchronous multi-region replication cannot enforce a unique username, because each region checks only its own rows before accepting. We compared a global reservation in a home region or consensus store, a partitioned namespace, and accept-and-repair, each paying in latency, availability or user trust. Because registration is rare and tolerates an extra 100 to 200 ms, a strongly consistent global reservation is usually right, with everything else, including profile reads, staying local.
Open with
The duplicates happened because each region enforces the unique constraint only on its own copy, and with asynchronous replication there's a window, here under a second, in which both regions check, find nothing and commit.
Then, if they want more
To actually enforce uniqueness, the decision for a name has to be made in one place. Option one is a global reservation table in a strongly consistent store, either in a home region or in something consensus-based like Spanner or CockroachDB spanning regions. Registration inserts the name there first and then creates the profile locally.
That costs a cross-region round trip at registration, and registration fails or waits if that store is unreachable. Option two partitions the namespace by hash so each region owns a share of names and registrations are routed to the owner; it spreads load but most registrations still pay a round trip and rebalancing is complex.
Option three accepts duplicates and repairs them with a deterministic rename, which is only acceptable when names can change and aren't used in links or mentions.
Since registration is rare and users won't notice 100 to 200 milliseconds once, I'd choose the global reservation, ideally in a consensus-backed store so it survives losing one region, and keep all profile reads and other writes local.
About this answer
- Last updated
- 13 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 official documentation for the version you use. 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 "Design username uniqueness for this multi-region setup, and explain the latency and...": https://scrivio-interview-library.netlify.app/architecture/partitioning-and-replication/7e09504a46/