Distributed ReliabilityRetry, idempotency and ownershipPrincipal
How can regional failover avoid duplicate external writes when a stale worker is still running?
By Amit Kumar4 min readWorked answer includedReviewed 26 Sept 2026
The question
Interview question
An agent in region A may create an external ticket or refund. Region A loses connectivity, and region B takes over from an asynchronously replicated checkpoint while A’s worker may still run. Design the operation identity, ownership and recovery protocol. The external provider does not accept your fencing token. Explain how the answer changes if B’s checkpoint predates the operation record or the provider cannot reliably deduplicate or report the outcome.
Draft your approach first
Take a few minutes before you read the answer. Name the constraint that matters most, the failure you are designing for and how you would know it worked.
Reveal the worked answerWorked answer
Regional failover must answer two different questions: who may continue local work, and whether the external action already happened. Giving region B ownership does not cancel a request that region A sent earlier. A safe design needs an authoritative decision about local operation identity and a separate way to handle uncertainty at the external provider.
Start with one business intent. A refund requested for a particular payment should receive one stable operation identity before any region sends it. Record the target, amount, currency, authorization and argument fingerprint with that identity. Both regions must recover the same operation, rather than derive new identities from worker attempts. A deterministic identifier can help with repeat discovery, but it cannot by itself prove that the intended operation or its exact arguments were committed.
Use an authoritative operation ledger and ownership protocol for the pre-send decision. If the required contract is at most one accepted intent, a region isolated from that authority cannot independently approve a conflicting intent and still preserve the guarantee. It must stop that class of writes. Asynchronous checkpoints can remain useful for resumable computation, but they are insufficient as the sole authority for irreversible effects when failover may omit recent decisions.
A lease gives a worker temporary ownership. An epoch or fencing token is an increasing ownership number attached to its state changes. When B acquires a newer epoch, the ledger rejects updates from A's older epoch. This prevents a paused old worker from overwriting local results after it wakes. Google's Chubby paper provides a concrete distributed-lock design and discusses mechanisms for stale clients. Our operation protocol still has to enforce its own ownership checks.
The provider in the question does not check our fencing token. A can therefore send a request just before losing ownership, or its already sent request can reach the provider afterward. The database can reject A's later success update without undoing that refund. This is the gap between controlling a local record and controlling an external effect. A replacement worker must treat a recorded attempt without a confirmed result as potentially committed.
Provider deduplication can bridge some of that gap. Both regions use the same provider idempotency key for the same operation and parameters within its documented scope and retention. B may then repeat an attempt without creating a second effect under that contract. If the provider offers a reliable lookup by operation reference, B can reconcile before sending anything. A confirmed external result is recorded in the ledger and lets the workflow continue without another write.
Lookup requires careful interpretation. A missing result in a delayed replica is not definitive evidence of absence. Likewise, two locally serialized workers do not prevent a late request already in flight from arriving after a negative lookup. Automatic retry is safe only if the combined provider and protocol guarantees rule out a duplicate, for example through deduplication covering all attempts. Otherwise the unknown state must remain unresolved until sufficient evidence exists.
Now suppose B's checkpoint predates the operation record. If a strongly authoritative ledger survived, B can discover the accepted intent there before continuing. If the ledger also exists only in A with asynchronous replication, B cannot infer from absence that nothing was sent. A provider query may resolve the outcome, but an unavailable or incomplete query does not justify a fresh submission. Record the uncertainty and pause. This limitation belongs in the promised failover behavior before an incident.
If the provider supplies neither fencing, reliable deduplication nor adequate outcome evidence, fully automatic safe replay is impossible for that ambiguous effect. Route the case to a controlled manual resolution process or use a different business contract that explicitly tolerates and reconciles duplicates. A compensating action is itself a new external operation and may fail. It cannot supply proof that the first action did not happen.
This design sacrifices write availability during some partitions. That is a deliberate consequence of preserving one authoritative decision for consequential work, not a defect that adding another region automatically solves. Low-risk reads or reversible computations may continue under a different policy. Keep those decisions separate from refund authority.
Test with a provider simulator and two workers. Pause A before send, after send, after provider commit and before local success. Promote B from a stale checkpoint, then let A wake. Verify shared operation identity, rejection of stale ledger updates and no unsafe new submission while the provider outcome is unknown. Track unresolved-operation age and resolution workload as well as failover time. Temporal's Activity guidance recommends idempotent effects under retries, but a workflow engine cannot manufacture an external provider guarantee.
Related questions
Keep practising distributed reliability
Follow another question in this area, or search the complete library.
Get my essays on AI engineering and distributed systems by email. Subscribe to ArchCrux