Overview
A single-region transactional platform fails in two ways: a regional outage takes everything down, and the regulator or the board starts asking about your business continuity plan before the all-clear. Resilience rules for critical services — DORA and the EBA guidelines in the EU, the FCA’s operational resilience regime, SAMA’s business continuity framework, and sector equivalents in energy, telecoms and healthcare — converge on the same expectation: critical systems must have recovery capabilities that deliver defined RPO and RTO targets across a declared secondary site. Most organisations start by deploying a warm standby in a second availability zone or data centre. The engineering question — which almost always surfaces too late — is what “in sync” actually means when you have two live copies of business-critical data separated by 20 milliseconds of WAN latency.
This article walks through the three main topologies, the conflict problem that every active/active deployment eventually hits, the specific configuration paths for Kafka and Postgres (the two platforms most commonly found alongside IBM MQ and Db2 in large enterprise estates), and the observability you need to detect drift before it becomes a reconciliation incident.
A replicated second site copies deletes. If a buggy process or a runaway batch drops rows, the replica follows. Replication and backup solve different problems; you need both, with different retention horizons and independent restore paths. A business continuity audit will ask for both.
Topology choice
Three topologies dominate in practice. Choose before you build anything else — the replication mechanism, the conflict strategy, and the failover runbook all follow from this decision.
The two patterns that cause the most trouble in production are optimistic active/active (teams assume conflicts won’t happen because they partition by customer) and passive standby treated as hot (the DBA sets the standby to accept reads under normal load, but the failover runbook still assumes it needs a 15-minute warm-up). Both reveal themselves at incident time.
Conflict resolution
Conflicts in active/active arise when two regions write to the same logical row before either replication stream catches up. Four resolution strategies, from weakest to most reliable:
| Strategy | Mechanism | Safe for | Dangerous for |
|---|---|---|---|
| Last-Write-Wins (LWW) | Higher timestamp overwrites | User profile fields, preferences | Balances, counters |
| Region priority | Nominated region always wins | Non-symmetric writes | True active/active workloads |
| Merge / CRDT | Commutative op applied both sides | Additive counters, sets | Complex business objects |
| Application-layer resolution | Conflict queued; business logic resolves | Ledger entries, payments | High-volume, latency-sensitive paths |
Last-write-wins on a balance field silently drops concurrent credit and debit operations. If Region A processes a credit of 500 at 14:00:01.001 and Region B processes a debit of 200 at 14:00:01.003, the Region B write wins and the credit disappears from the customer’s ledger. This is not a corner case — it is the normal operating condition of an active/active payment platform under load. Never use LWW on monetary fields.
The most reliable pattern for balances, ledgers and stock levels in active/active is write partitioning by entity: each entity (account, customer, order, SKU) is owned by exactly one region for writes, regardless of where reads are served. Conflicts become structurally impossible because the owning region is the single writer. The complexity shifts to routing: the application must know which region owns a given entity and route write requests accordingly — across regional boundaries if necessary.
Kafka MirrorMaker 2
MirrorMaker 2 (MM2) is the Kafka-native solution for cross-cluster topic replication. It runs inside Kafka Connect and supports bidirectional replication with offset translation — the critical feature that lets consumers in Region B resume at the correct offset after a failover, rather than replaying from the beginning of the mirrored topic.
# MirrorMaker 2 (connect-mirror-maker.properties) - bidirectional east <-> west
clusters = east, west
east.bootstrap.servers = kafka-east.svc.internal:9093
west.bootstrap.servers = kafka-west.svc.internal:9093
# TLS between regions - expected for regulated data in transit
east.security.protocol = SSL
west.security.protocol = SSL
east.ssl.truststore.location = /certs/east.truststore.jks
west.ssl.truststore.location = /certs/west.truststore.jks
east.ssl.keystore.location = /certs/east.keystore.jks
west.ssl.keystore.location = /certs/west.keystore.jks
# Enable both directions
east->west.enabled = true
west->east.enabled = true
# Topics to replicate - an explicit allow-list beats a deny-list for regulated data
east->west.topics = payment\.events, customer\.events, limit\.events
west->east.topics = payment\.events, customer\.events, limit\.events
# Offset translation - critical for failover without replay
east->west.sync.group.offsets.enabled = true
west->east.sync.group.offsets.enabled = true
east->west.emit.checkpoints.enabled = true
west->east.emit.checkpoints.enabled = true
east->west.emit.heartbeats.enabled = true
west->east.emit.heartbeats.enabled = true
# Replication factor for mirrored topics in the target cluster
replication.factor = 3
# MM2 has no lag-threshold or throttling setting. Watch lag through its metrics instead:
# MirrorSourceConnector replication-latency-ms (max/avg), record-age-ms (max/avg)
# MirrorCheckpointConnector checkpoint-latency-ms
# exposed over JMX as kafka.connect.mirror:type=MirrorSourceConnector,target=*,topic=*,partition=*
# Alert when replication-latency-ms max stays above your RPO budget (e.g. 20 s for instant payments).
MM2’s default replication policy prefixes remote topics with their source alias (east.payment.events on the west cluster), and its cycle detection skips topics that originated in the cluster it is writing to — so a default bidirectional setup does not loop. The trap is IdentityReplicationPolicy, which keeps topic names unchanged: MM2 can no longer tell a mirror from an original, so it is suitable only for one-way replication. Keep the default policy for active/active, and still prefer an explicit topic allow-list for regulated data.
Database replication
Kafka handles event streams. The relational database holding the ledger, account state, and customer master needs its own cross-region strategy. Two platforms common in large enterprise estates are PostgreSQL (for newer microservices) and IBM Db2 (often underneath legacy systems of record). Each has a distinct replication path.
PostgreSQL streaming replication is the default HA mechanism: the primary streams WAL to one or more standbys in real time. Standbys are read-only until promoted. Synchronous replication is decided on the primary: a standby named in synchronous_standby_names must confirm each commit. With synchronous_commit = on the commit waits until the WAL is flushed on the synchronous standby (zero RPO); remote_apply also waits until the change is visible there, which matters only if you read from that standby. Making a cross-region standby synchronous puts a WAN round-trip on every write. To keep it asynchronous, leave it out of synchronous_standby_names and measure its lag via pg_stat_replication.replay_lag.
# --- primary (east region) ---
wal_level = replica
max_wal_senders = 5
wal_keep_size = 1024MB
wal_log_hints = on # lets pg_rewind re-sync this node after a failover
# Only the local standby is synchronous. A standby listed after it inside FIRST 1 (...)
# is a *potential* sync standby: it would become synchronous if the local one dropped
# out, putting a WAN round-trip on every commit. Leave the cross-region standby out.
synchronous_standby_names = 'FIRST 1 (standby_local)'
synchronous_commit = on # commit waits for WAL flush on standby_local: zero RPO in-region
# --- standbys (standby_local, standby_west) ---
hot_standby = on # allow read-only queries on the standby
hot_standby_feedback = on # fewer query cancellations on the standby, at the cost of primary bloat
# recovery_target_timeline defaults to 'latest' (PostgreSQL 12+): standbys follow a promotion
Patroni is the recommended HA layer for Postgres in Kubernetes. It wraps streaming replication with automatic leader election (backed by etcd or Consul), a REST health endpoint, and a switchover/failover CLI. Cross-region Patroni requires that your distributed consensus store (etcd) also spans regions, with an odd number of members across three locations — for example two per region plus a tiebreaker at a third site. With only two locations, losing the one that holds the etcd majority stops automatic failover.
IBM Db2 HADR is the IBM-native solution for Db2 HA/DR. Configure HADR with HADR_SYNCMODE NEARSYNC (primary waits for the log to reach the standby buffer but not be applied) for a good balance between RPO and WAN round-trip cost. SUPERASYNC gives the lowest latency but risks losing the in-flight log on primary failure.
# On the primary (east region) - Db2 CLP commands run from the shell
db2 "UPDATE DB CFG FOR PAYMENTSDB USING
HADR_LOCAL_HOST db2-primary.east.svc.internal HADR_LOCAL_SVC 50900
HADR_REMOTE_HOST db2-standby.west.svc.internal HADR_REMOTE_SVC 50901
HADR_REMOTE_INST db2inst1
HADR_SYNCMODE NEARSYNC
HADR_TIMEOUT 120
HADR_PEER_WINDOW 120"
# HADR_PEER_WINDOW: after losing the standby, the primary blocks commits for up to 120 s,
# so a TAKEOVER HADR ... BY FORCE PEER WINDOW ONLY on the standby cannot lose committed work.
db2 "START HADR ON DB PAYMENTSDB AS PRIMARY"
# Monitor replication health (role, state, log gap) from either side
db2pd -db PAYMENTSDB -hadr
-
Enable cross-region connectivity
Open the HADR port (Db2: TCP/50900–50901, Postgres: TCP/5432) between data centres. Use TLS/mTLS for the replication stream — unencrypted replication of regulated data over a WAN is a control failure under almost any regulatory framework.
-
Take a base backup to the standby
Postgres:
pg_basebackup -h primary -D /var/lib/postgresql/data -P -R. Db2: offline backup restore ordb2inidbstandby initialisation. -
Start replication and verify lag
Postgres:
SELECT * FROM pg_stat_replicationon primary; checksent_lsn - replay_lsn. Db2:db2pd -db PAYMENTSDB -hadr(or theMON_GET_HADRtable function) and check the HADR state and log gap. -
Configure automatic failover
Postgres with Patroni: leader election is automatic when the primary fails a health check. Db2: use a cluster manager with quorum — the integrated Pacemaker support in recent Db2 11.5 releases, or TSA through
db2haicu— rather than a home-grown script callingTAKEOVER HADR ON DB. Either way, automated takeover must fence the old primary to prevent split-brain. -
Test failover end-to-end quarterly
Perform a planned switchover, measure actual RTO, verify the application reconnects correctly, and walk the standby back to primary. Simulate network partition, not just a clean shutdown. Regulators and auditors expect evidence of tested DR procedures.
-
Document failback
After a failover, the old primary becomes the new standby. Re-sync it from the new primary (another base backup or HADR reinitialisation) before promoting it back. Skipping this step causes divergent timelines and data loss.
Consistency & RPO/RTO
CAP theorem in a WAN multi-region deployment resolves to: you either sacrifice consistency (allow stale reads or lost writes during a partition) or availability (wait for confirmation from the second region before committing). Systems of record — ledgers, inventory, billing and policy systems — almost universally choose the latter for write paths: the record must be correct, and brief unavailability is preferable to a wrong balance or a double-sold item.
Translate this into concrete targets:
- RPO (Recovery Point Objective) — how much data can be lost. For instant payments and other system-of-record writes: effectively zero (synchronous replication). For analytics and reporting replicas: seconds to minutes.
- RTO (Recovery Time Objective) — how long until the service is back. Patroni-managed Postgres: roughly the leader-key TTL plus promotion time — with the
ttl: 60shown below, budget about a minute; shorter TTLs fail over faster but are more sensitive to WAN blips. Manual Db2 HADR takeover: minutes. Application-level reconnect logic adds another 10–60 seconds to the RTO you present to the business.
Postgres streaming replication lag is not the same as application-observed RPO. Between the last WAL write on the primary and the moment a consumer in Region B reads the replicated row, there is also: WAL transmission time, standby apply time, and Debezium CDC lag if events are involved. Measure end-to-end data age under load, not just pg_stat_replication.replay_lag.
Failover & failback
Automated failover requires three things to be in place before the incident: a consensus mechanism that detects failure faster than the timeout, a promotion sequence that does not cause split-brain, and application-layer reconnection logic that handles the new primary endpoint without a restart.
The most common production failure in multi-region deployments is the network partition that is not a real primary failure. The primary is up in Region A; the standby in Region B cannot see it due to a WAN link issue. If the standby promotes itself, both regions believe they are primary. Both write. Replication resumes when the link recovers, and the two divergent timelines must be reconciled manually — with potentially lost or duplicated payment records. The prevention is quorum plus fencing. With Patroni, the leader lock lives in etcd: a primary that cannot renew its leader key demotes itself, and a replica promotes only after that key has expired (a watchdog makes the self-demotion enforceable). With Db2 HADR, the cluster manager provides quorum and fencing, and BY FORCE PEER WINDOW ONLY restricts a forced takeover to the window in which no committed transactions can be lost.
scope: payments-cluster
name: pg-west-standby
etcd3:
hosts: etcd-east.svc:2379,etcd-west.svc:2379,etcd-witness.svc:2379 # one member per region + a witness site
bootstrap:
dcs:
ttl: 60 # leader key TTL; standby waits this long before considering failover
loop_wait: 10
retry_timeout: 30
maximum_lag_on_failover: 1048576 # 1 MB; beyond this, standby will NOT auto-promote
synchronous_mode: true # only acked standbys eligible for promotion
postgresql:
parameters:
synchronous_commit: remote_apply # zero RPO for synchronous standby
wal_level: replica
hot_standby: "on"
use_pg_rewind: true # fast re-sync of old primary after failback
Failback is the step most runbooks skip. After a failover, the old primary is stale. The fastest path back: use pg_rewind (configured in Patroni as use_pg_rewind: true) to re-sync it from the new primary’s divergence point rather than running a full base backup. pg_rewind needs data checksums or wal_log_hints = on on the old primary, and the WAL since the divergence point must still be available; otherwise a fresh base backup is required. Either way, test failback in the DR exercise, not just failover.
Data residency
Data-residency rules — financial-sector cloud frameworks such as SAMA’s Cloud Computing Regulatory Framework, national data-protection laws, public-sector and health-data rules — typically impose three constraints on cross-region replication for regulated data:
- Data must remain within the jurisdiction. Both the primary and the replication target must sit in in-country data centres or an approved cloud region inside the jurisdiction. Replicating to a region outside it — even as a cold DR copy — typically requires an explicit regulatory approval or exemption.
- Encryption in transit is mandatory. All replication streams crossing any network segment — even private links between data centres — must use TLS 1.2+ with a certificate chain the organisation controls. Certificate expiry on a replication channel has caused production incidents; automate rotation.
- Audit trails must be replicated. If the primary fails, the regulator expects the audit log to survive with zero gaps. A separate replication stream for audit tables (or a Kafka topic used exclusively for audit events) with a stronger consistency guarantee than the main data replication is the correct design. Separating audit from operational data in the replication architecture also makes the compliance evidence cleaner.
Regulators and governments update their lists of approved cloud providers and regions. If your DR site is in an approved cloud region, track the relevant regulatory notifications and build a review step into your annual DR testing cycle to confirm the region is still approved. Cloud-hosted DR that relied on a region later removed from an approved list is a classic source of compliance findings.
Observability
Cross-region replication fails silently. The primary keeps writing; the standby falls behind; the lag alert is not set; the DBA discovers the standby is 4 hours behind when they need it for a planned maintenance failover. The minimum instrumentation every multi-region deployment must have:
# Metric names depend on your exporters (postgres_exporter, JMX exporter rules for
# Kafka Connect / MirrorMaker 2, a Db2 exporter). Treat the names below as placeholders.
groups:
- name: replication
rules:
# Postgres streaming replication lag > 30 s -> page
- alert: PostgresReplicationLagHigh
expr: pg_replication_lag_seconds{standby="west"} > 30
for: 2m
labels:
severity: critical
annotations:
summary: "Postgres cross-region standby lag {{ $value }}s - RPO budget at risk"
# MM2 replication latency (MirrorSourceConnector replication-latency-ms, max) > 20 s
- alert: MM2ReplicationLatencyHigh
expr: max by (topic) (kafka_connect_mirror_source_connector_replication_latency_ms_max) > 20000
for: 5m
labels:
severity: warning
annotations:
summary: "MM2 replication latency {{ $value }} ms on {{ $labels.topic }} - check WAN link and connector tasks"
# MM2 heartbeats stop arriving in the target cluster -> replication is down
- alert: MM2HeartbeatMissing
expr: time() - mm2_heartbeat_last_seen_timestamp_seconds > 60
for: 1m
labels:
severity: critical
annotations:
summary: "MM2 heartbeat absent - cross-region Kafka replication down"
# Db2 HADR log gap > 10 MB -> warn
- alert: Db2HADRLogGapHigh
expr: db2_hadr_log_gap_bytes > 10485760
for: 3m
labels:
severity: warning
annotations:
summary: "Db2 HADR log gap {{ $value | humanize }} - standby drifting"
Beyond lag, build a data-age dashboard: pick a high-write table (e.g., payment_transactions), track the timestamp of its most recent row on both primary and standby, and alert if the standby’s most recent row is more than N seconds older than the primary’s. Replication metrics at the platform layer (LSN, log gap) measure pipe capacity; data-age metrics measure actual business impact.
Decision guide
Choosing between active/passive, active/hot-standby, and active/active comes down to four questions. Answer them in order — the topology falls out:
-
What is the maximum acceptable data loss (RPO)?
Zero RPO → synchronous replication required → WAN round-trip adds to every write latency → active/hot-standby with
synchronous_commit = remote_apply. Non-zero RPO (e.g., 5 s for analytics) → async replication → all three topologies are viable. -
Can the second region serve live reads under normal operation?
Yes → active/hot-standby or active/active. No → active/passive. Hot-standby reads with slight lag are acceptable for most reference data; they are not acceptable for balance reads that precede an authorisation decision.
-
Do multiple regions receive independent writes to the same data?
Yes → active/active, with mandatory write partitioning or conflict resolution. No → one of the simpler topologies. If you cannot answer “no” with confidence, you do not yet have the write ownership model required for active/active and should not proceed.
-
What is the operational cost ceiling?
Active/active adds conflict resolution logic, write-routing infrastructure, and significantly more complex failover testing. As a planning assumption, expect it to cost several times the engineering effort of active/passive. If that budget is not approved, active/hot-standby delivers most of the availability improvement at a fraction of the cost.
-
Does the regulator require tested DR within a defined RTO?
Most regulators require regulated firms to document and test business continuity plans. If your approved RTO is under 30 minutes, active/passive with manual failover is likely insufficient — Patroni-automated Postgres failover or a tested Db2 HADR takeover procedure is required.
In practice, successful active/active deployments almost always start life as active/passive or active/hot-standby. The teams that shipped active/active reliably understood their write ownership model completely before they changed the topology. Teams that started with active/active as a design goal without that foundation spent years firefighting conflict incidents. The topology is not a statement of ambition; it is a consequence of operational readiness.