SDI.
All Concepts
Databaseshigh-availabilityprimary-replicasynchronousasynchronousWALfailoverread-replicasconsensus

Database Replication

Database replication copies data from one database server (primary) to one or more others (replicas) to provide high availability, fault tolerance, and read scalability.

Replication keeps multiple copies of data across database instances. The most common model is primary-replica (formerly master-slave): one primary handles all writes, and replicas asynchronously receive a copy of every write for read scaling and failover. Synchronous replication guarantees no data loss but adds write latency; asynchronous replication is faster but risks losing recent writes on failover. Multi-primary (multi-master) allows writes on any node but introduces conflict resolution complexity.

Tradeoffs

Strengths

  • High availability: Replicas can take over if the primary fails, achieving 99.99%+ uptime.
  • Read scalability: Adding replicas linearly increases read throughput.
  • Disaster recovery: Replicas in different regions protect against datacenter-level failures.
  • Backup offloading: Run backups from a replica instead of the primary.
  • Geographic performance: Place replicas near users for low-latency reads.

Weaknesses

  • Write bottleneck: In primary-replica, all writes go through a single primary.
  • Replication lag: Async replication means replicas may serve stale data.
  • Failover complexity: Automated failover can go wrong (split-brain, data loss, stale reads).
  • Storage cost: Each replica is a full copy of the data (double or triple the storage).
  • Consistency trade-offs: Sync replication adds latency; async replication risks data loss.
  • Operational complexity: Managing replication topology, monitoring lag, handling divergent timelines.

Likely Follow-Up Questions

  • How do you handle replication lag in a read-after-write scenario?
  • What happens during a failover when the primary has unreplicated writes?
  • When would you use synchronous vs. asynchronous replication?
  • How does Raft consensus provide stronger guarantees than primary-replica replication?
  • What are the trade-offs of multi-primary replication?
  • How would you design a database replication strategy for a multi-region application?

Source: editorial — Synthesized from PostgreSQL and MySQL replication documentation, GitHub/Instagram engineering blogs, and distributed database literature (Raft, Paxos).

Command Palette

Search for a command to run...