Database Replication

Databases
06 / 21

Copy your data to multiple servers to achieve fault tolerance, read scaling, and geographic distribution.

PRIMARY(Writes)REPLICA 1REPLICA 2Replication Log
SD blueprint: Active-Standby Replication
The Analogy (Read This First)

A newspaper company (Primary) prints the daily paper. It sends copies to hundreds of newsstands (Replicas) across the city. Readers can buy from any newsstand nearby - no need to travel to the print shop. If the print shop burns down, all the newsstands still have yesterday's paper.

Deep Dive Analysis

Single-Leader (Master-Replica) Replication: One designated node accepts all writes (the leader/primary). It continuously ships write events to one or more follower nodes. Followers are read-only - they replicate and serve reads. This is PostgreSQL streaming replication, MySQL binlog replication, and Redis Sentinel.

This pattern dramatically improves read throughput: you can have 5 replicas and spread your read queries across all 6 nodes (1 primary + 5 replicas). Write throughput is unchanged because all writes still go through one node.

Synchronous vs Asynchronous replication: Synchronous means the primary waits for at least one replica to acknowledge every write before confirming success to the client. Zero data loss, but higher write latency. Asynchronous means the primary confirms immediately and replicates in the background - lower latency, but potential data loss if the primary crashes before the replica catches up.

Multi-Leader Replication: Multiple nodes accept writes. Used for multi-datacenter setups (one leader per data center). Each leader asynchronously replicates to the others. The trade-off: write conflicts can occur when the same row is modified simultaneously in two data centers.

Leaderless Replication (Dynamo-style): Used by Cassandra, Riak, DynamoDB. Any node can accept writes. The client writes to W nodes and reads from R nodes. If W + R > N (total nodes), you are guaranteed to read at least one up-to-date value. This enables extremely high availability - no single leader to fail.

Key Bullets
  • Primary goal: fault tolerance - if the primary fails, promote a replica.
  • Secondary goal: read scaling - distribute reads across replicas.
  • Replication lag: replicas may be seconds behind the primary (problematic for "read your own writes").
  • Automatic failover (sentinel, orchestrator) needed in production.
  • RPO (Recovery Point Objective) = max data loss tolerable. Sync replication = RPO of 0.
Trade-offs
Sync replication: zero data loss, higher write latencyAsync replication: low latency, risk of losing last N writes on crashMulti-leader: low-latency multi-region writes, complex conflict resolution
Real-World Examples
PostgreSQL: built-in streaming replicationMySQL: binlog-based replication (semi-sync in production)Cassandra: leaderless with tunable consistency (ONE, QUORUM, ALL)MongoDB: replica sets with automatic failover

Curated Curation & Deep Insights

ScaleDojo Certified
Video Tutorial Pending

Our system architects are vetting high-quality, authorized video guides for Database Replication with zero third-party platform links.

Verification in Progress
Reading Material Pending

We are preparing premium, zero-competitor deep-dives for Database Replication. Authorized reading references will appear automatically.

Verification in Progress
ScaleDojo Logo
Initializing ScaleDojo