Notesreplication🌱 seedling

Synchronous vs Asynchronous Replication

Also: Synchronous Replication · Asynchronous Replication · Semi-Synchronous Replication · Semisync

Whether the leader waits for followers before telling the client a write succeeded. Synchronous buys durability with latency and availability; asynchronous buys speed with the risk of losing acknowledged writes.

Why it exists

"OK" has to mean something. If it means "on the leader's disk", a leader crash before shipping loses the write. If it means "on every follower's disk", one slow follower stalls every write.

How it works

  • Synchronous: the leader replies only after a follower confirms it has the write.
  • Asynchronous: the leader replies once its own disk has it and ships in the background.
  • Semi-synchronous: one follower is synchronous, the rest asynchronous; if the sync one fails, another is promoted to sync. An acknowledged write is on at least two nodes.
  • Quorum commit: wait for any k of a set (PostgreSQL ANY 2 (a, b, c)), so one slow follower doesn't matter.
  • How far the follower got also matters: received, written to OS, flushed to disk, or applied and visible to queries.

Trade-offs

Mode Gains Costs
synchronous (all) no acknowledged write lost any follower can halt writes
semi-sync / quorum durability on 2+ nodes, tolerates a slow follower a round trip per commit
asynchronous lowest latency, never blocks recent acknowledged writes can be lost on failover

In practice

  • PostgreSQL synchronous_commit: remote_write (standby OS has it), on (standby flushed it), remote_apply (standby replayed it, so reads there see it), local/off (don't wait). Settable per transaction.
  • MySQL semisync waits after syncing the binlog but before the engine commits (AFTER_SYNC, the default) for one replica by default. After rpl_semi_sync_source_timeout (10 s by default) with no acknowledgement, it falls back to asynchronous until a replica catches up.

Pitfalls

  • Semi-sync that silently degrades to async changes your durability guarantee with no client-visible error. Alert on it.
  • "Synchronous" in one system can mean "received" and in another "applied". Check which.

Recall

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