What it is
With asynchronous replication the primary commits a write locally, acknowledges it to the client, and sends the change to its replicas afterwards. Replicas apply the stream in order and are always somewhat behind. It is the default in PostgreSQL streaming replication and MySQL replication, and the usual mode for cross-region copies in managed databases.
The Database Replication lesson shows that async replicas lag and can serve stale reads. This lesson looks at why lag grows, what a replica outage really costs, and how much confirmed data a failover can lose.
Why it exists
Because it keeps replicas out of the write path. A write takes as long as the local commit, however many replicas there are and however far away they are, and a slow or dead replica never blocks a write. For most data a short, measured window of possible loss and slightly old reads is a better deal than paying replica latency and replica availability on every write.
How it works
The write path. Client → primary → local commit (log flushed on the primary) → acknowledgement. In parallel, a sender process streams the log to each replica. The lesson shows the response leaving the primary before the replication packets arrive, even at replicas 2 ms away.
Lag. Each replica is behind by network delay plus its queue of unapplied changes. A replica in another region is behind by at least the one-way delay. Lag is usually measured as time (PostgreSQL pg_stat_replication.replay_lag, a heartbeat row written every second and read on the replica) or as log distance (bytes or LSN difference, GTID sets). MySQL's Seconds_Behind_Source is based on event timestamps and can mislead around idle periods and long transactions; a heartbeat table (as pt-heartbeat does) is more reliable.
Why lag grows under write load. The primary executes writes on many connections in parallel. Replay is far less parallel: PostgreSQL's standby replays WAL in a single startup process, and MySQL's multi-threaded applier runs a limited number of workers (replica_parallel_workers, 4 by default since 8.0.27) constrained by transaction dependencies. A write burst, a large batch update, or a long-running query on the replica that conflicts with replay (PostgreSQL max_standby_streaming_delay) all grow the backlog. The primary keeps going; the replica falls further behind; nothing fails.
Replica outages. The primary keeps the log a disconnected replica still needs: a PostgreSQL replication slot retains WAL until the replica confirms it; MySQL keeps binlogs until they expire. A long outage fills the primary's disk unless retention is capped (max_slot_wal_keep_size, binlog_expire_logs_seconds), and a replica that falls past the cap must be rebuilt from a fresh copy. A replica that returns in time replays the backlog at its normal replay speed while new changes keep arriving, so its lag drains slowly: two seconds of outage can take several seconds to make up.
Failover and the loss window. If the primary dies, changes it acknowledged but had not yet shipped exist nowhere else. Promote a replica and they are gone. Roughly, data at risk ≈ write rate × lag at the moment of the crash: 240 writes/s with 450 ms of lag puts about 100 confirmed writes at risk. In the lesson those writes touch about 50 hot keys, and promoting a replica leaves each of them with an older value than the one its writer was told was saved. That is the recovery point objective (RPO) async replication gives you, and it is largest exactly when lag spikes.
When to use it
- The default for read replicas, analytics copies and cross-region disaster recovery.
- When write latency matters and a small, measured RPO is acceptable.
- When replicas are far away or numerous, so waiting for them would be slow or fragile.
When not to
- For data where an acknowledged write must never be lost (payments, ledgers, orders): add a semi-sync or synchronous replica nearby, or use a consensus-replicated store.
- For reads that must reflect the latest write: route them to the primary, or wait for the replica to reach the write's log position.
- When replicas routinely lag by minutes and the application cannot tolerate it: fix the cause (replay parallelism, long queries, undersized replicas) before adding more.
Trade-offs
| Aspect | Async | Sync / semi-sync |
|---|---|---|
| Write latency | Local commit only | Plus the round trip to the replica(s) waited for |
| Replica outage | No effect on writes; primary retains log | Blocks or slows writes unless the set adapts |
| Replica freshness | Behind by lag; stale reads possible | Fresh only for replicas waited for at apply level |
| Data loss on failover | Up to write rate × lag | None for the covered failures |
| Distant replicas | Fine | Expensive on every write |
Alternatives
- Semi-synchronous or quorum commit to one nearby replica, with remote copies left async.
- Synchronous replication for small, critical datasets.
- Consensus-replicated databases (CockroachDB, Spanner, YugabyteDB) that commit on a majority.
- Shared replicated storage (Aurora, AlloyDB), where durability comes from the storage layer and read replicas lag only in their caches.
- Logical replication / change data capture for feeding other systems, with the same async lag characteristics.
Failure modes
- Silent lag spikes. Batch jobs, schema changes or long replica queries push lag from milliseconds to minutes; dashboards based on latency and errors stay green.
- Loss of acknowledged writes on failover, sized by lag at the time.
- Disk exhaustion on the primary from WAL retained for a dead replica's slot.
- Replica too far behind to catch up from retained logs; needs a rebuild, during which read capacity is reduced.
- Promoting the wrong replica: one that is further behind than another loses more data than necessary.
- Stale reads after writes for users routed to replicas (read-your-writes), covered in the Replication Lag lesson.
In production
Alert on replication lag per replica (time and bytes), not just on replica health. Remove a replica from read rotation when its lag exceeds what readers tolerate (ProxySQL max_replication_lag, custom health checks). Cap retained WAL or binlogs so a dead replica cannot take the primary down. On failover, promote the replica with the highest replayed position; tools like Patroni and Orchestrator do this and can refuse to promote a replica lagging more than a configured threshold (Patroni maximum_lag_on_failover). Write down the RPO you actually have, measured from lag percentiles during your busiest jobs, and add a semi-sync replica where that RPO is not acceptable.
Common misconceptions
- "Async replicas are a few milliseconds behind." In steady state, often. Under write bursts or long replica queries, lag can reach seconds or minutes.
- "If it was acknowledged, it's durable." On one machine. Lose that machine before shipping and the write is gone.
- "A dead async replica is harmless." Writes are fine, but the primary retains its log; left long enough, that can fill the disk.
- "More replicas reduce lag." Each replica has its own lag; adding replicas changes nothing about how fast any one of them replays.
Interview angle
Default to async replicas for reads and DR, then show you know its price. Quantify the loss window ("about 1,000 writes/s × typical 100 ms lag ≈ 100 writes at risk, more during batch jobs"), say how you would monitor lag, and name the mitigations: promote the most caught-up replica, alert and throttle when lag grows, route read-your-writes traffic to the primary, and add a semi-sync replica in another zone for data that cannot be lost. Mentioning replication slot retention or replay parallelism signals real operational experience.
Model assumptions
The simulation is a simplified model, not a benchmark. Every database has 12 connections, a 30 ms mean read and a 15 ms mean write (lognormal, cv 0.4). The app tier sends 400 queries/s, 30% writes, over 300 keys (Zipf 1.0); a proxy sends writes to the primary and reads to Replicas 1 and 2 by least connections. The primary answers at its local commit and ships each change to every replica after the network hop (2 ms in Region A, 70 ms to Replica 3 in Region B). Each replica replays changes one after another, at most 200 per second, so lag is the hop plus replay time plus the queue in front of replay: about 10 ms normally, growing without bound while writes exceed 200 per second. The primary keeps the log for a replica that is down and sends it when the replica returns (catch-up); disk usage of that log is not modelled. When the primary crashes, changes it had not yet delivered are lost. Promotion is a modelled failover: the promoted replica takes over the replication links and settings, the proxy sends writes to it, and the simulation counts the keys whose latest acknowledged write the promoted replica never applied (several lost writes to one hot key count once). A read is stale when the replica has not applied a write the primary had already acknowledged for that key. Not modelled: choosing the most caught-up replica, fencing, and the time detection and promotion take in practice. Numbers show behaviour and orders of magnitude only.