Replication keeps identical data on several nodes: one node accepts changes and the others repeat them locally. This lets a database survive a server failure without stopping the service, and spreads reads across several copies.
Primary and replicas
The classic scheme is one primary (a master) and several replicas (standbys). All writes go through the primary: it applies a change and records it in its log — the write-ahead log, the binary log or the operation log. The replicas read this log and repeat the same changes locally, so their copies usually lag behind the primary by fractions of a second.
| System | What is sent to replicas |
|---|---|
| PostgreSQL | a stream of WAL records — the write-ahead log |
| MySQL | binary log (binlog) events |
| MongoDB | the operation log (oplog) |
| Redis | a stream of the commands applied by the primary |
There is also a multi-primary scheme, where several nodes accept writes at once, but it requires conflict resolution and is used less often.
Synchronous and asynchronous
- Asynchronous: the primary acknowledges a write straight away, without waiting for the replicas. Fast, but if the primary fails the last writes can be lost.
- Synchronous: the primary waits for an acknowledgement from a replica and only then commits the transaction. Writes are not lost, but every write costs at least one round trip between nodes.
Intermediate modes exist almost everywhere: in PostgreSQL the synchronous_standby_names parameter makes every commit wait until a replica has written the commit record to its own disk. In MySQL semi-synchronous replication waits for an acknowledgement from at least one replica. In Kafka the producer chooses the acknowledgement level itself: with acks=all a write counts as successful once every replica in the in-sync set (ISR) has confirmed it, so with a replication factor of 3 and min.insync.replicas=2 it survives the failure of one broker out of three.
What it gives and what it costs
The main benefit is availability: when the primary fails, a replica is promoted to the new primary and the service keeps running. The second is read scaling: reports and heavy queries go to the replicas. The price is replication lag: a user who has just written data may not see it on the next request if the answer came from a replica that has not caught up yet. Replication is no substitute for backups: mistakenly deleted data spreads to every copy at once.
Sources
the term is written from these pages- PostgreSQL 18 — High Availability, Load Balancing, and Replicationpostgresql.org/docs/current/warm-standby.html(opens in a new tab)
- MySQL 8.4 Reference Manual — Replicationdev.mysql.com/doc/refman/8.4/en/replication.html(opens in a new tab)
- Confluent — Kafka Broker Configs: min.insync.replicasdocs.confluent.io/platform/current/installation/configuration/broker-configs.html(opens in a new tab)
Verified 9 Nov