agentsclimarketplace

Replication patterns

Skill jacob-balslev/skills/skills/data-engineering/replication-patterns

Public Agent Skills library exported from skill-graph. Install: npx skills add jacob-balslev/skills

Install
npx -y skills add jacob-balslev/skills --skill replication-patterns

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

What its author says it does

Copied from the file, not written here

Use when designing how a database keeps multiple copies of its data in agreement across nodes for availability, read scaling, and disaster recovery: the three foundational topologies (single-leader / primary-replica, multi-leader / multi-primary, leaderless / quorum), synchronous vs asynchronous replication and the replication-lag trade-off, log shipping vs statement replication vs trigger-based replication, the read-after-write consistency problem and its mitigations (sticky session, read-from-leader, monotonic reads), the failover model and split-brain risk, and the relationship to the CAP/PACELC choices the topology realizes. Do NOT use for horizontal partitioning across nodes (use sharding-strategy), the CAP theoretical frame itself (use cap-theorem-tradeoffs), single-node transactional guarantees (use transaction-isolation), or query tuning (use query-optimization).

The file declares its own license as MIT. That is the author’s claim about this one file, and it is not the same thing as the license GitHub reports for the repository, which is listed with the other numbers below.

SKILL.md

23.5 KB, ~2.3k tokens by cl100k_base, as published. Nobody here has run it

Concept of the skill

What it is: Replication is the design discipline for keeping multiple copies of the same data on multiple nodes so a database can survive failures, scale reads, or place data near users.

Mental model: The core choices are topology, synchrony, replication mechanism, read-freshness policy, failover policy, and conflict handling. Single-leader systems serialize writes through one primary, multi-leader systems accept writes in more than one place and must merge conflicts, and leaderless systems use quorums so clients can read or write through multiple nodes.

Why it exists: A single database copy creates one point of failure and one read bottleneck. Replication adds resilience and scale, but it also creates lag, failover, stale-read, and split-brain risks that the application must deliberately handle.

What it is NOT: It is not sharding, which splits different data across nodes. It is not CAP theory itself, single-node ACID guarantees, isolation-level selection, query tuning, indexing, or backups.

Adjacent concepts: sharding-strategy partitions data; cap-theorem-tradeoffs names the consistency/availability frame; transaction-isolation and transaction-isolation describe local transaction guarantees; backup and restore practice protects against replicated corruption or deletion.

One-line analogy: Replication is like keeping synchronized copies of a critical operations log in several control rooms: the system keeps working when one room fails, but everyone needs rules for who may write, how copies catch up, and who takes charge after an outage.

Common misconception: Turning replication on does not automatically create zero data loss, fresh reads, safe failover, or backups; each of those safety properties requires an explicit topology, synchrony, routing, fencing, monitoring, and recovery choice.

Replication Patterns

Coverage

The catalog of replication topologies and the operational discipline that makes them work in production. Covers the three foundational topologies (single-leader / primary-replica, multi-leader / multi-primary, leaderless / quorum), the synchrony spectrum (sync, semi-sync, async, quorum-sync), the mechanism choices (statement-based, row-based, trigger-based, logical, physical), the read-after-write consistency problem and its mitigations (sticky session, read-from-leader, monotonic reads, version tokens), the failover model and quorum-based split-brain prevention, the conflict-resolution choices in multi-leader and leaderless systems (LWW, CRDTs, vector clocks, application merge), and the relationship to the CAP/PACELC choices the topology realizes.

Philosophy of the skill

Replication is the discipline that gives a database fault tolerance, read scaling, and disaster recovery — at the cost of consistency-handling, conflict resolution, and operational complexity.

The default starting point is single-leader with asynchronous replication: simple, well-understood, sufficient for most read-mostly workloads. The departures from this default — multi-leader, leaderless, synchronous, geographic — each address a specific requirement (multi-region writes, strong consistency under partition, RPO=0) and add proportional complexity.

The most common production failures are not in the replication topology itself but in the application's handling of its consequences: stale reads producing user-visible bugs, split brain producing silent data divergence, failover producing unrehearsed surprises. The discipline is treating replication as an architecture the application is co-designed with, not a database feature that handles itself.

Topology Selection

TopologyBest forTrade-offs
Single-leader, asyncRead-heavy workloads with tolerance for stale readsReplication lag; possible data loss on leader failure
Single-leader, syncWorkloads requiring RPO=0Write latency; replica failure can block writes
Multi-leaderMulti-region writes; active-active disaster recoveryConflict resolution complexity
Leaderless (quorum)High availability with tunable consistencyRead latency = slowest of R; quorum-sizing decisions
Synchronous via Raft/Paxos (Spanner, CockroachDB)Strong consistency at scaleHigh write latency for distant replicas

The starting point for most workloads is single-leader async; depart from this default only when the workload requires it.

Synchronous vs Asynchronous Trade-off

PropertySynchronousAsynchronous
Write latencyHigher (waits for replica)Lower (acks immediately)
RPO (data loss on failure)ZeroUp to lag window
Read consistency from replicasStrongEventual
Replica failure impactCan block writesNone
Use caseHigh-stakes financial transactions, strong-RPO systemsMost production read-replicas

Semi-sync (wait for one replica with timeout-to-async fallback) is the middle ground; production-default for many systems.

Read-After-Write Mitigations

MitigationHow it worksCost
Read-from-leader for a window after writeClient routes back to leader for N secondsLoses read scaling for write-heavy users
Sticky sessionClient always reads from same replicaReplica failure invalidates session
Monotonic readsClient tracks last-seen version; replica must be ≥ that freshRequires version-token plumbing
Wait-for-replicaClient waits until replica catches upAdds latency to the read
Accept stale readsApplication tolerates stalenessOnly viable when stale data is OK

Every read-mostly workload with async replicas must choose one. Defaulting to "read from any replica" produces stale-data bugs.

Failover and Split-Brain Prevention

MechanismSplit-brain riskUsed by
Manual operator failoverNone (if procedure is correct)Small / legacy systems
Heuristic auto-failover (no quorum)High under partitionOlder Postgres tools (without proper consensus)
Quorum-based promotion (Raft / Paxos)Eliminated by majority requirementModern HA tools (Patroni, etcd, CockroachDB internal)
STONITH fencingOld leader killed; cannot continue writingPacemaker / Corosync HA

A system that must not split-brain uses quorum-based promotion. The cost is requiring an odd number of voting nodes ≥ 3.

Verification

After applying this skill, verify:

  • The replication topology is intentional and documented: single-leader / multi-leader / leaderless; sync / async / semi-sync; physical / logical / trigger-based.
  • Read-after-write consistency is handled explicitly. Sticky session, read-from-leader, monotonic reads, version tokens, or accept-stale is a named choice.
  • Replication lag is monitored. Lag thresholds trigger alerts before users notice.
  • Failover procedure is documented, tested, and rehearsed. Untested failover is failover that fails first time.
  • Split-brain prevention uses quorum-based promotion for any system requiring it. Heuristic failover is recognized as risky.
  • Backups exist separately from replication. Replica state and backup state are distinguished.
  • For multi-leader: the conflict resolution mechanism (LWW / CRDT / vector clocks / app merge) is defined and tested with concurrent-write scenarios.
  • For leaderless: W and R values are chosen for the workload's consistency-vs-latency target; W+R>N if strong consistency is required.
  • Cross-region replication latency is measured and accepted as part of the design budget.

Do NOT Use When

Instead of this skillUseWhy
Horizontally partitioning data across nodessharding-strategysharding partitions data; replication copies it
Reasoning about the CAP/PACELC theoretical framecap-theorem-tradeoffsCAP names the trade-off; this skill realizes it
Single-node transactional guaranteestransaction-isolationACID is the single-system frame
Choosing isolation levelstransaction-isolationtransaction-isolation owns concurrency; this owns multi-node
Indexingindexing-strategyindexing is within-node retrieval
Tuning a slow queryquery-optimizationquery-optimization is per-query

Key Sources

What ships with it: 4 files

23.3 KB alongside SKILL.md

Keep looking

Skills are one crate of 326,984. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.