| name | data-replication |
| description | Design data replication strategies for high availability, read scaling, and disaster recovery. Outputs replication topology, consistency model, failover procedures, and lag monitoring setup. |
| argument-hint | ["database type","consistency requirements","read/write ratio","RTO/RPO targets","geographic distribution"] |
| allowed-tools | Read, Write |
Data Replication
Data replication maintains copies of data across multiple nodes to achieve read scaling, high availability, and disaster recovery. The fundamental tension is between consistency (all replicas have the same data) and availability (reads and writes succeed even when nodes fail).
Replication Topologies
1. Single-leader (Primary/Replica)
Primary: all writes
Replicas: read scale + failover
Consistency: eventual (async) or synchronous (1+ replica)
2. Multi-leader
Multiple nodes accept writes
Conflict resolution required
Use: multi-datacenter, offline-capable clients
3. Leaderless (Dynamo-style)
Any node accepts reads and writes
Quorum: W + R > N for consistency
Use: Cassandra, DynamoDB, Riak
PostgreSQL Streaming Replication
wal_level = replica
max_wal_senders = 5
max_replication_slots = 5
wal_keep_size GB
synchronous_commit
synchronous_standby_names
host replication replicator replica1_ip scramsha
host replication replicator replica2_ip scramsha
replicator REPLICATION LOGIN ENCRYPTED PASSWORD ;
primary_conninfo
primary_slot_name
hot_standby
hot_standby_feedback
client_addr, state, sent_lsn, write_lsn, flush_lsn, replay_lsn,
(sent_lsn replay_lsn) replication_lag_bytes,
(epoch (now() replay_lag)) lag_seconds
pg_stat_replication;
pg_create_physical_replication_slot();
slot_name, active, pg_wal_lsn_diff(pg_current_wal_lsn(), restart_lsn) lag_bytes
pg_replication_slots;