Logical vs Physical Replication for Multi‑Region SaaS: trade‑offs
We’re running a SaaS that serves users in North America, Europe, and APAC. Our primary goal is sub‑100 ms read latency for each region while keeping write ordering guarantees across the fleet. PostgreSQL gives us two ways to keep data in sync: physical streaming replication (the classic hot‑standby setup) and logical replication (row‑level streaming via replication slots).
Physical streaming is simple to configure – a base backup plus primary_conninfo on the replica. It ships WAL bytes verbatim, so failover is fast and data loss is minimal when using synchronous mode. The downside is that the replica must be an exact copy: same major version, same schema, and you cannot cherry‑pick tables. Bandwidth usage can be high, and cross‑region latency shows up as replication lag that directly impacts read freshness.
Logical replication lets us replicate only the tables we need, and it tolerates minor version differences. We can add a new column on the primary without touching the subscriber, which is a big win for rolling schema migrations. However, each logical slot adds CPU overhead, and async delivery means a small window of potential data loss. Conflict resolution is left to the application, and monitoring slot health is an extra operational burden.
-- Create a logical slot for the EU region
SELECT * FROM pg_create_logical_replication_slot('region_eu', 'pgoutput');
-- Subscribe to the slot
CREATE SUBSCRIPTION eu_sub
CONNECTION 'host=primary port=5432 dbname=app user=replicator password=***'
PUBLICATION my_pub;
Quick trade‑off list
- Latency: logical can be tuned per‑table, physical ships all WAL.
- Failover: physical sync gives <5 s RTO; logical needs slot re‑creation.
- Schema changes: logical wins, physical forces a full dump/reload.
- Ops overhead: physical is “set‑and‑forget”, logical adds slot monitoring.
Questions for the community
- What real‑world RTO have you seen when failing over a logical replica across continents compared to a physical one?
- How do you handle rolling schema migrations (e.g., adding columns) when you have many logical subscriptions in production?
0 Answers
Post Your Answer
Use ``` code ``` for syntax highlighting