CSE Roadmap

Common tier · about 2 hours · 5 parts

Part 4 of 5 · 2 min read

Failover, and the synchronous-versus-asynchronous trade-off

Promoting the standby risks losing whatever log entries had not yet arrived, a risk synchronous replication reduces at a real latency cost.

Failover, and the synchronous-versus-asynchronous trade-off

Think of the understudy actually stepping onto the stage when the lead actor collapses. There is a risk of having missed the very last line spoken just before the switch, if that line's audio had not quite reached backstage yet.

In plain words: failover is the process of promoting a standby to become the new primary after the original primary fails. If any log entries were in transit, sent by the primary but not yet received and replayed by the standby at the moment of failure, those changes can be lost during failover. Synchronous replication reduces this risk by having the primary wait for the standby's confirmation before considering a transaction committed, guaranteeing no committed transaction is ever lost, but at the cost of added latency on every single commit, since the primary must wait for that round trip every time. Asynchronous replication skips that wait, keeping commits fast, but accepts the small risk of losing the most recent transactions if failover happens at an unlucky moment.

A worked example. Under synchronous replication, a commit is only considered successful once the standby has confirmed receiving it, so failover never loses a committed transaction, but every commit pays the cost of that confirmation round trip; under asynchronous replication, commits return immediately, but a failover could lose whichever transactions were still in transit at that exact moment.

The key lines. No new SQL; the choice between synchronous and asynchronous replication is a configuration setting on the replication link between primary and standby.

Failover, synchronous versus asynchronous replication

Failover promotes a standby to primary after a failure, risking loss of any log entries still in transit at that moment; synchronous replication eliminates that risk at the cost of commit latency, while asynchronous replication keeps commits fast but accepts that small risk.

Example: an understudy stepping in but possibly missing the very last line not yet heard over the audio feed mirrors the risk failover carries without synchronous confirmation.

Remember this

A standby, kept in sync via continuous log shipping, exists to make recovery from a primary failure far faster than a backup restore. The synchronous-versus-asynchronous choice is a direct trade-off between commit latency and the risk of losing the most recent transactions during failover, matching every durability-versus-performance trade-off covered across this entire level.

Quick notes

  • A standby is a separate, running copy, continuously kept up to date, ready to take over much faster than a backup restore.
  • A standby stays current via log shipping: continuously receiving and replaying the primary's write-ahead log.
  • Failover promotes a standby to primary, risking loss of any log entries still in transit at that moment.
  • Synchronous replication eliminates that loss risk at the cost of added commit latency.
  • Asynchronous replication keeps commits fast but accepts a small risk of losing the most recent transactions on failover.