Video in progress

The application has to run in two regions. How do you evaluate active-passive and active-active options with PostgreSQL?

Active-passive is simple and consistent, but writing from the far region is slow and a little data may be lost on failover. Active-active needs conflict resolution; with PostgreSQL I do it only when the data is partitioned by region.

📖 Answer

First I ask: why is multi-region needed, for disaster recovery (DR) or for low latency for users? In many cases only DR is needed, and that's much cheaper.

Active-passive:

  • The primary is in region A, with an asynchronous replica in B (if synchronous, 30-100 ms on every commit).
  • The application in B reads from the local replica and sends writes to A, so write latency is cross-region.
  • If the region is lost: promote B, with RPO = the replica lag (usually seconds). The decision is often manual, because automatic region failover raises the risk of split brain.

Active-active:

  • Writes in both regions. PostgreSQL itself has no ready-made multi-master; there are solutions like bidirectional logical replication (in PG 16+ origin = none prevents loops), pgEdge, and BDR.
  • If one row is changed in two regions at the same time, that's a conflict. "Last writer wins" is unacceptable for money.

My practical approach is to split the data by owner (home region): each user belongs to one region, and their writes happen only there. That's really sharding by region; there's no conflict, because one row is written by one region. Global data (the catalog, settings) is written in one region and distributed to everyone.

If you truly need globally consistent writes, I'd look at systems like Spanner or CockroachDB rather than PostgreSQL, but after measuring their cost, latency and SQL compatibility.