advanced

Replication

Use replication for availability and read scale while accounting for lag, failover, conflicts, and read consistency.

Replication copies data from a primary to one or more replicas for read scale, availability, and geographic distribution. Models: async (common, lag tolerated), sync (stronger durability, higher write latency), multi-primary (conflict resolution required).

					write → primary → replication stream → replica(s) → read traffic
				

Failover promotes a replica when the primary fails — requires health checks, split-brain guards, and application connection handling. Reads from replicas may be stale; route only eventually-consistent queries there.

On interviews: explain replication lag symptoms (user sees old balance); contrast replication with backups; describe failover steps and what breaks if DNS or pooler caches old primary.

Common pitfalls: reading your writes from async replica; no monitoring of lag seconds; automatic failover without fencing; treating cross-region replica as zero RPO; schema drift between nodes.

The trade-off is read throughput and availability versus consistency lag, conflict complexity, and failover operational risk.

Checklist:

  • Name sync vs async replication.
  • State which reads tolerate staleness.
  • Monitor replication lag and alerts.
  • Document failover and connection drain.
  • Distinguish replica from backup.