Notesreplication🌱 seedling

Multi-Leader Replication

Also: Multi-Master Replication · Active-Active Replication · Multi-Primary Replication

Several nodes, typically one per region or per device, each accept writes and asynchronously forward them to the others. Writes are local and survive outages, at the cost of [[Write Conflict]]s.

Why it exists

A single leader makes every write pay the round trip to it, makes it a write single point of failure, and can't serve a client that's offline. A leader per region (or per device) removes all three.

How it works

  • Inside each region, ordinary Leader-Based Replication; between regions, leaders exchange changes asynchronously.
  • Offline clients are the same pattern: each device's local database is a leader that syncs later. Collaborative editing is the extreme case.
  • Topologies: all-to-all (robust, but messages can overtake each other, so an update can arrive before its insert), ring or star (simpler, but one failed node breaks the flow).
  • Each change records the nodes it passed through so it doesn't loop.

Trade-offs

Gains Costs
local write latency conflicts, resolved asynchronously
no failover: regions keep writing through outages weaker invariants (uniqueness, constraints)
offline operation complex topology and ordering issues

In practice

  • DynamoDB global tables (default mode) replicate between Regions typically within a second and resolve concurrent writes per item by Last Write Wins.
  • PostgreSQL 16 added origin = none subscriptions, enabling loop-free two-way logical replication; PostgreSQL 18 detects and logs conflicts but doesn't resolve them.

Pitfalls

  • "Conflict avoidance" by routing each record to a home region fails exactly when that region fails over.
  • Auto-increment keys, triggers and constraints behave surprisingly across leaders.

Recall

These cards are also in your review deck, scheduled with spaced repetition.