Sub topic 3
Replicating Events and Messages Between Regions
Assume you know basic DNS, load balancers, stateless services, and database replication. This chapter focuses on the control-plane problems that appear after several regions serve traffic at once.
Replicate events, not every message
An event records something that already happened, such as OrderCreated. A message asks a consumer to perform work. Both can cross regions through a replicated log or message broker.
Use asynchronous replication when a request cannot wait for another region. The local region accepts the work, stores an event durably, and forwards it. Consumers must tolerate delay, duplicates, and reordering.
sequenceDiagram
participant Client
participant EU as EU service
participant Log as Replicated event log
participant US as US consumer
Client->>EU: Create order
EU->>Log: Store OrderCreated
Log-->>US: Replicate event
US->>US: Apply eventIdempotency and safe retries
An idempotent operation has the same effect when run multiple times. Attach a unique idempotency key to each request. Store the key with the result in durable, replicated storage. A retry then returns the stored result instead of charging or creating the resource again.
The key store must remain available during failover. If each region has a separate key store, the same retry can be applied twice.
Failure modes and capacity
A regional outage may stop traffic, replication, or both. A partial failure can leave the region reachable while its database or event link is broken. Split brain occurs when two sides believe they may accept conflicting writes.
Use ownership rules, fencing, or quorum decisions for data that cannot safely accept concurrent writes. Size the surviving regions for the outage case, not only normal traffic. If three regions each run at 50% capacity, losing one leaves the remaining two at 75%, assuming traffic redistributes evenly.
Observability and testing
Measure replication lag, consumer age, duplicate rate, retry count, rejected writes, and traffic by region. Test DNS or load-balancer failover, delayed links, isolated databases, and recovery of a failed region. Verify both data convergence and business effects such as one payment per order.
Data residency, cost, and fit
Data-residency rules may require personal data to remain in a country or legal region. Replicate only permitted fields, or keep regulated data in its owning region and send redacted events.
Active-active increases network, storage, monitoring, testing, and operational costs. Choose active-passive when rare failover, simpler writes, or strict residency rules matter more than continuous regional capacity and lower latency.
Exercise
A payment event may be delivered twice after a regional failover. What prevents a second charge?
Show answer
A shared durable idempotency key records the first successful operation, so the retry returns that result without charging again.