Primary/replica architecture and sync vs async replication
coreintermediateA primary/replica setup has one instance (the primary) that accepts writes, and one or more replicas that receive a continuous copy of those writes. Synchronous replication waits for a replica to confirm before the primary reports success — safer, slower. Asynchronous replication reports success immediately and streams the change to replicas afterward — faster, with a real chance of losing the most recent writes if the primary fails first.
Think of it as
The primary is the one person allowed to write the master copy of a shared document. Synchronous replication is calling a colleague and waiting for them to confirm they've copied your latest edit before you tell your boss it's done. Asynchronous replication is telling your boss it's done immediately, and separately emailing the colleague the update — usually fine, but if you get hit by a bus between hitting send and the colleague reading it, your latest edit exists nowhere else.
What we're doing: Show why asynchronous replication can lose the most recent write during a primary failure.
- 2
- The client is told the write succeeded here — before any replica has it.
- 6
- This is the actual data loss: a write the client was told succeeded is now unrecoverable.
Why this works: This gap between "confirmed to the client" and "durable on more than one node" is exactly what synchronous replication closes, at the cost of extra write latency — the trade-off has to be made deliberately, not discovered during an incident.
Assuming a replica set automatically means no data loss on failover
Wrong
Better
What you see: After a failover, a small number of recently "successful" writes are missing on the newly promoted primary — surprising to a team that assumed replication alone guaranteed durability.
Why: Replication's durability guarantee depends entirely on whether it is synchronous — most systems default to asynchronous replication for performance, which means the guarantee most people assume ("replicated means safe") does not actually hold without an explicit choice to pay the synchronous latency cost.
- Client — writes
- leads to Primary (write)
- Primary — accepts the write
- leads to Replica (replicate)
- on error, leads to Confirm (async) (immediately)
- Confirm (sync) — after replica ack
- Confirm (async) — before replica has it
- Replica — receives the stream
- leads to Confirm (sync) (ack received)
Synchronous vs asynchronous replication
Remember: Primary accepts writes, replicas receive a stream of them. Synchronous replication waits for a replica ack before confirming (safer, slower); asynchronous confirms immediately (faster, can lose the newest writes on failover).
See also: read replicas and consistency · replication lag

