Quick revision
The short answer
The payments that were written in the failed region just before the failover had idempotency records that had not yet replicated, so when clients retried in the new region, the key was unknown and the payment ran again. Asynchronous replication means a recovery point objective above zero for idempotency data as well as payments. To survive failover, the key store must be as durable and consistent as the payments it protects: keep keys in the same strongly consistent store as the payment, replicate that store synchronously or by quorum, or pin clients to a home region; also pass the key to the payment provider, and reconcile after every failover.
What to remember
In this answer, we saw that asynchronous replication left idempotency records written just before the failure only in the failed region, so retries in the new region ran the payment again. We recapped RPO and stated the rule that the key store must be as durable as the payments, compared synchronous or quorum replication of a shared store with home-region routing and controlled failover, added provider-side idempotency keys as a downstream safety net, and closed with reconciliation and failover rehearsals with retries in flight.
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 payments that were written in the failed region just before the failover had idempotency records that had not yet replicated, so when clients retried in the new region, the key was unknown and the payment ran again. Asynchronous replication means a recovery point objective above zero for idempotency data as well as payments. To survive failover, the key store must be as durable and consistent as the payments it protects: keep keys in the same strongly consistent store as the payment, replicate that store synchronously or by quorum, or pin clients to a home region; also pass the key to the payment provider, and reconcile after every failover.
Why this question is asked
Idempotency is usually designed inside one region, where the database that holds the keys is the same database that holds the payments. Multi-region setups break that quiet assumption, and the failure shows up only on the worst day, during a failover with requests in flight. This scenario is common in interviews for senior roles because it tests whether we can reason about replication lag, recovery point objectives and layered defences together. In this answer, we will reconstruct how 1,200 duplicates appeared, recap RPO and asynchronous replication, compare the designs that close the gap, add downstream deduplication, and finish with reconciliation and rehearsal.
1How the Failover Produced Duplicates
In an active-passive setup, all traffic goes to region A, and region B receives a copy of the data by asynchronous replication: A commits locally, answers the client, and ships the change to B a little later, typically tens or hundreds of milliseconds. During normal operation that lag is invisible.
Now region A fails. Some requests were in flight: their payment had been processed and their idempotency record written in A, but the client never received the response, so it retried. Some of those records had not reached B yet. Traffic moved to B, the retry arrived with the same key, B looked up the key, found nothing, and processed the payment again. The client did everything right; the server simply forgot. Whether the first payment survived depends on whether the payment row itself replicated or whether the money movement happened at an external provider, which is why the duplicates showed up as real double charges.
2A Quick Recap of RPO and Asynchronous Replication
The recovery point objective (RPO) is how much recent data we may lose in a disaster, measured in time. Asynchronous replication gives an RPO above zero: whatever was committed in the last moments before the failure may be gone. Teams usually accept that for some data, such as analytics events. But idempotency records are the safety net of payments; if they are less durable than the payments they protect, a failover turns into duplicates. The rule is simple: the key store must be at least as durable and consistent as the data it protects, and committed at the same moment.
9 messages in order. Play them, or step through them one at a time.
The record of K existed only in region A when it failed.
3Designs That Close the Gap
The first option is to keep idempotency records in the same strongly consistent store as the payment and commit them together. If that store is replicated synchronously or by quorum across regions, for example a distributed SQL database such as CockroachDB or Spanner, or PostgreSQL with a synchronous standby in the other region, a committed payment and its key exist in both places before the client gets a response. The cost is write latency: every commit waits for a cross-region round trip.
The second option is to keep replication asynchronous but control where a client's requests go. Each client or account has a home region, and requests go there. During a controlled failover, we stop accepting writes in the old region, wait until replication has caught up, and only then move traffic. Retries never land in a region that has not seen the key. In an uncontrolled failure we cannot wait, so this needs a fallback, which is the next section.
A third pattern is to synchronously replicate only the small idempotency store, while bulk data stays asynchronous. That shrinks the latency cost but brings back the gap between the payment row and the key; it works only if the key's record is enough to answer a retry, for example it holds the provider's charge id.
| Design | Extra latency | Duplicates after unplanned failover | Complexity |
|---|---|---|---|
| Keys async, per region (today) | none | yes, for in-flight requests | low |
| Same store, synchronous or quorum | one cross-region round trip, about 20-80 ms | no | medium |
| Home region + controlled failover | none | no in planned failover; possible in unplanned | medium |
| Downstream key at provider | none | caught by provider | low, always add it |
4Deduplicating Downstream as Well
Defence in depth matters here. Payment providers such as Stripe and Adyen accept idempotency keys of their own. If we pass our key, or a key derived from it such as a hash of client id and key, when we call the provider, then the retry in region B that tries to charge again sends the same provider key, and the provider returns the original charge instead of creating a second one. Our records may have been lost, but the provider remembers. This one change would likely have prevented most of the 1,200 duplicates, and it costs nothing in latency. The provider's retention window must cover our failover time, which it usually does by a wide margin.
5Reconciliation and Rehearsal
No design removes every risk, so after any failover we run reconciliation: compare our payment records with the provider's settlement reports for the window around the failover, find charges with the same client key or same customer, amount and merchant within a short interval, and refund the duplicates proactively, before customers notice. Doing this automatically turns a failover from an incident into a routine.
Finally, failover must be rehearsed with retries in flight, not with an idle system. A game day that kills region A while a load generator sends payments and retries with keys is the only way to see whether the design holds. The test that ran before this incident probably failed over a quiet system, which is why the gap stayed hidden.
6Follow-up questions
What latency would synchronous replication between regions add, and is it acceptable here?
Each commit waits for at least one round trip to the other region, plus the time for the standby to write its log. Between two regions on the same continent that is roughly 20 to 80 milliseconds; across an ocean, 100 milliseconds or more. A payment API usually already waits several hundred milliseconds for the card network, so adding 30 to 60 milliseconds to make duplicates impossible is normally acceptable. It would not be acceptable for, say, a high-frequency internal API, which is why we apply it only to the payment path, keep the regions close, and measure p99 after the change.
Should the client do anything differently?
The client already reused its key, which was correct. It could add a longer backoff before retrying after a connection failure, which gives a controlled failover time to complete, but the fix belongs on the server side.
7Conclusion
In this answer, we saw that asynchronous replication left idempotency records written just before the failure only in the failed region, so retries in the new region ran the payment again. We recapped RPO and stated the rule that the key store must be as durable as the payments, compared synchronous or quorum replication of a shared store with home-region routing and controlled failover, added provider-side idempotency keys as a downstream safety net, and closed with reconciliation and failover rehearsals with retries in flight.
Open with
The duplicates came from replication lag. In active-passive with asynchronous replication, region A committed some payments and their idempotency records, but the clients never got the responses, and those records had not reached region B when A failed.
Then, if they want more
The clients retried with the same keys, as they should, but B had never seen those keys, so it processed the payments again. In other words, our idempotency data had an RPO above zero, and that is not acceptable for data that protects payments. The key store has to be at least as durable and consistent as the payment itself.
So I would keep the idempotency record in the same store as the payment and commit them together, and make that store synchronously or quorum replicated across regions, which costs one cross-region round trip, a few tens of milliseconds, which is fine next to card network latency.
Alternatively, each client has a home region and we only move traffic after replication catches up, though that only helps for controlled failovers. Independently of that, I would pass our key, or a derived id, to the payment provider, which supports idempotency keys, so a duplicate charge attempt is caught downstream.
And after any failover I would run reconciliation against the provider's records to find and refund duplicates, and rehearse failover with retries in flight.
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 "Explain how the failover produced duplicates, and design idempotency that survives...": https://scrivio-interview-library.netlify.app/architecture/api-design-at-scale/b841290938/