Quick revision
The short answer
The system chose availability over consistency: during the split each region kept accepting writes without coordinating with the other, so both sold the same last 5 units and the item oversold. To change it, we can give each item a home region that is the only writer of its stock, use a consensus-based database for stock and accept higher latency, or split the stock into per-region quotas; or we keep availability and compensate with back-orders or cancellations if the business accepts that. The right design chooses per data type, strong consistency for stock and payments and availability for carts and catalog reads, and the partition behaviour is documented and tested with fault injection.
What to remember
In this answer, we saw that two regions selling the last units during a split means the system chose availability over consistency, often by default. We can restore correctness with a home region per item, a consensus-based database or regional stock quotas, each paying in latency, availability or stranded stock, or keep availability and compensate with back-orders and cancellations. The choice belongs to each data type, strong for stock and payments and available for carts and catalog, and the partition behaviour must be documented and tested with fault injection.
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.
The system chose availability over consistency: during the split each region kept accepting writes without coordinating with the other, so both sold the same last 5 units and the item oversold. To change it, we can give each item a home region that is the only writer of its stock, use a consensus-based database for stock and accept higher latency, or split the stock into per-region quotas; or we keep availability and compensate with back-orders or cancellations if the business accepts that. The right design chooses per data type, strong consistency for stock and payments and availability for carts and catalog reads, and the partition behaviour is documented and tested with fault injection.
Why this question is asked
Multi-region databases are sold on the promise that each region keeps working when the other is unreachable. That promise has a price, and an inventory count is where it shows: two regions that cannot talk cannot both know how many units are left. Interviewers ask this scenario to see whether we can name the trade-off that was made, often without anyone deciding it, and redesign so that the system's behaviour during a split is a business decision rather than an accident. In this answer, we will replay what happened during the split, name the trade-off, go through the design options with their costs, see why the choice should be made per data type, and finish with documenting and testing it.
1Replaying What Happened
Before the split, stock for item 501 is 5 in both regions, because the database replicates writes between them, usually asynchronously so that local writes stay fast. Then the network link between the regions fails. Both regions are still running and still serving customers in their area. Region A receives orders for 4 units and region B for 3. Each region checks its local copy, sees enough stock, decrements it and confirms. When the link returns, replication merges the changes, and the stock is 5 - 4 - 3 = -2: seven units sold, five available.
8 messages in order. Play them, or step through them one at a time.
Each region decided alone on a copy that was out of date.
2Naming the Trade-off
In CAP terms, during a network partition a system must choose between consistency, every read seeing the latest write, and availability, every region answering requests. This system chose availability: both regions kept answering and accepting writes, so neither could see the other's sales. Often nobody chose it explicitly; it came with the database's default multi-region mode or with asynchronous replication. Even without a partition, the same problem can appear in a smaller window, because asynchronous replication takes time and two orders in different regions a few hundred milliseconds apart can also both pass the check.
So the question is not how to fix a bug in the stock code, but which behaviour we want for stock when regions disagree, and what we are willing to pay for it.
3Option 1: A Home Region per Item
We give every item a home region that is the only place its stock can be changed. Item 501 might live in region A. An order in region B for that item forwards the reservation to region A, which applies it with a conditional update, so stock can never go below zero.
Notice that this is a single writer: consistency is easy because there is only one copy that decides. The cost is latency for orders placed outside the home region, one cross-region round trip, and availability: during a split, region B cannot sell items whose home is A.
4Option 2: A Consensus-Based Database or Regional Quotas
A consensus-based database, such as Spanner, CockroachDB or another system built on Paxos or Raft, commits a write only when a majority of replicas agree. With replicas in three regions, any single region can be cut off and the other two keep a consistent, writable stock, while the isolated region refuses stock writes. Every write pays at least one cross-region round trip, tens of milliseconds, and we need at least three locations to tolerate losing one.
Stock quotas, sometimes called escrow, split the stock between regions ahead of time: of 5 units, region A may sell 3 and region B 2. Each region sells only from its own quota, without coordination, so even during a split nothing oversells. When a region runs low, it asks the other to transfer part of its quota, which needs the link. This keeps orders fast and local, but an item can show 'sold out' in one region while units remain in the other, so it works best for items with plenty of stock and gets awkward for the last few units.
| Option | Oversell? | Cost | During a split |
|---|---|---|---|
| Home region per item | No | Cross-region latency for remote orders | Remote region cannot sell |
| Consensus database | No | Round trip on every write | Minority region refuses writes |
| Regional quotas | No | Stranded stock in one region | Each sells its own quota |
| Accept and compensate | Yes, bounded | Cancellations, customer impact | Both keep selling |
5Option 3: Accept and Compensate
Sometimes the best answer is to keep availability and handle the rare oversell afterwards. If splits last minutes a few times a year and most items have large stock, overselling is rare, and the business may prefer never refusing an order. Then we design the compensation: detect negative stock when regions reconcile, decide which orders to fulfil, typically first come first served by timestamp, and turn the others into back-orders with a delivery estimate or cancel them with an apology and a voucher. This is a business decision, so the product owner signs off on the policy and its cost, and we monitor how often it happens.
6Choosing per Data Type
Not all data in the shop needs the same guarantee, and treating it all the same makes everything either slow or unsafe. Stock reservations and payments, where a wrong answer costs money or trust, get strong consistency through a home region or a consensus store. Shopping carts can stay available and merge after a split, because a duplicated cart item is easy to fix. Catalog reads, prices shown on a page and recommendations can be served from local replicas and tolerate seconds of staleness, as long as checkout validates the price.
A common shape is: browse and cart locally in any region, and at checkout make one strongly consistent call for the reservation and the payment. Only that step pays the cross-region cost, and only it is unavailable in an isolated region.
- Does a wrong answer cost money or trust?YesStrong consistency: home region or consensusNoNext question
- Can conflicting writes be merged later?YesAvailable, merge after splitNoSingle writer per key
- Write the behaviour down and test itfault injection, game days
3 steps in order. Play them, or step through them one at a time.
7Documenting and Testing the Behaviour
Whatever we choose, the behaviour during a split must be written down where engineers and the business can see it: 'If region B loses contact with region A, region B can browse and fill carts but cannot complete checkout for items homed in A; customers see a retry message'. Then we prove it. Fault injection tools can block traffic between regions in a test environment, or in production during planned game days, and we check that stock never goes negative, that the error messages appear as designed, and that the system recovers when the link returns.
8Follow-up questions
How would you choose the home region for an item?
Usually the region where most of its demand comes from, or the region of the warehouse that ships it, since stock is physical. Items can move to a new home region with a short coordinated handover, for example by freezing writes for that item for a second while ownership changes.
Why not just reserve stock with a distributed lock?
A lock service is itself a distributed system that needs consensus to be safe, so during a split one side cannot get the lock, which is the consistency choice under another name. Using the database's conditional update in a single home region or a consensus database gives the same guarantee with fewer moving parts.
What changes if the item has 10,000 units instead of 5?
Quotas become very attractive: each region can hold thousands of units and sell locally, and a rebalancing job moves quota as demand shifts. The hard cases are only the last few units, where we can switch an item to home-region mode when its total stock falls below a threshold.
9Conclusion
In this answer, we saw that two regions selling the last units during a split means the system chose availability over consistency, often by default. We can restore correctness with a home region per item, a consensus-based database or regional stock quotas, each paying in latency, availability or stranded stock, or keep availability and compensate with back-orders and cancellations. The choice belongs to each data type, strong for stock and payments and available for carts and catalog, and the partition behaviour must be documented and tested with fault injection.
Open with
The system chose availability over consistency. During the split each region kept accepting orders against its own copy of the stock, and since replication between regions was down, neither knew about the other's sales, so both sold the last 5 units and we oversold.
Then, if they want more
To change that, I see a few options.
Each item can have a home region that is the only writer of its stock, using a conditional update like set available minus quantity where available is at least the quantity, so it cannot go negative; orders from the other region pay a cross-region round trip, and during a split they cannot buy items homed elsewhere.
A consensus-based database for stock commits through a majority of regions, so it is never inconsistent, but every write is slower and an isolated region refuses writes. Or we split stock into regional quotas, which keeps orders local but can leave stock stranded in one region.
If the business prefers never to refuse orders, we can accept rare oversells and compensate with back-orders or cancellations. I would choose per data type: strong consistency for stock reservations and payments at checkout, availability for carts and catalog reads. And I would document what happens during a split and test it with fault injection.
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
- Redis documentation, MongoDB 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 inventory service runs in two regions with a multi-region database. During a...": https://scrivio-interview-library.netlify.app/databases/nosql-fundamentals/f08c5720da/