Database replication: when do you need a copy?
Database replication propagates changes from one server to another so that the second server maintains a separate copy of the data. A standby may be promoted after a failure, or read requests may be distributed across replicas. But a replica is neither a perfectly current backup nor a universal way to accept writes safely on several servers. The purpose—high availability, read scaling, or data distribution—determines the replication method and the lag or data-loss risk you must accept.
What does replication copy?
In a common arrangement, one server accepts writes and records changes, while one or more replicas receive and apply them. The server playing the source role is often called the primary or source; a server following its changes is called a standby or replica. Names and topology vary by product, so check the database documentation instead of inferring behavior from terminology alone.
Replication usually has two stages. First, the primary records transaction changes in a log such as a write-ahead log (WAL) or binary log. Then a replica receives those records and applies them to its own data. A gap can therefore exist between the time a commit finishes on the primary and the time it can be read on a replica. Do not assume zero lag; define the delay the application can tolerate and its limit.
Write request --> Primary -- change log --> Replica
| |
+-- promotion candidate +-- read-scaling candidateWhat problems can replication solve?
Continue service after a failure
If a standby follows changes, it can be promoted to primary when the original server fails. This is one component of high availability (HA). Replication alone does not necessarily detect failure, fence the old server, promote a replacement, and redirect application connections. You also need a procedure for preventing split brain—two servers accepting writes at once—choosing a single leader, and recovering the old server.
With asynchronous replication, a commit that has not yet been sent or applied may be absent from the replacement after a failure. The amount of data you can lose at a failure point can be expressed as the recovery point objective (RPO), but actual RPO depends on configuration and failure conditions. Promoting a replica without confirming that it has caught up can lose missing transactions. After promotion, prevent the former primary from accepting writes and establish which server is authoritative.
Distribute read requests
Sending reports or search requests to read-only replicas can reduce read load on the primary. However, a write and the read that follows it may reach different servers. If a user saves a setting and immediately reads it from a replica, the old value may appear because the change has not been applied yet. Possible mitigations include routing that screen to the primary, waiting briefly for the change to reach a replica, or tracking a replication position in the session and selecting a replica that has replayed up to it.
Replicas can increase read throughput, but not every read is suitable for distribution. Reads that require strong freshness, read-after-write verification, long-running queries that interfere with replication apply, and business decisions that cannot tolerate stale results may need to go to the primary or use a separate policy. More replicas also add network, storage, monitoring, and change-propagation costs.
Use data at another site or in another system
Replication can also provide a copy to a remote office or an analytics environment. Decide which data is sent, how much lag is acceptable, and how deletions, schema changes, and privacy rules are reflected. This purpose has different requirements from failure recovery or online traffic distribution. Replicating data does not make the destination a replacement for the source or a recovery backup.
How do synchronous and asynchronous replication differ?
| Choice | When the write responds | Benefit | Cost and risk |
|---|---|---|---|
| Asynchronous | The primary can respond after commit without waiting for a replica to apply the change | Remote round trips are less likely to hold up the commit path | Read lag and possible loss of unapplied changes after failure |
| Synchronous | Commit waits until configured acknowledgement conditions are met | Can deliver a commit to the acknowledged replica and reduce loss risk | Network or replica failures can increase write latency or stop writes |
The word “synchronous” alone does not mean that every replica has applied a change immediately or that no failure can ever lose data. Check what the implementation waits for (log receipt, durable write, or transaction apply), how many acknowledgements are required, and whether writes continue when an acknowledging replica fails. PostgreSQL 18 documents how synchronization level changes the performance and data guarantees. Requiring more acknowledgements over a slow network can increase write latency. PostgreSQL 18: High Availability, Load Balancing, and Replication
What is the difference between physical and logical replication?
Physical replication propagates storage-level or database physical change records to maintain a server copy. PostgreSQL’s WAL-based standby is an example and follows the server as a whole. Depending on the configuration, a standby can operate as a hot standby and answer read-only queries. PostgreSQL 18’s comparison of replication solutions
Logical replication can send logical data changes, such as inserts, updates, and deletes of table rows, between a publisher and subscriber. It may be useful for selecting tables or feeding separate analytics and integration flows. It requires separate consideration of initial data copy, schema changes, primary keys and conflicts, and objects that are not replicated. PostgreSQL documents that logical replication can be controlled at table granularity. Physical and logical are not a ranking of “safer” versus “less safe”; they differ in propagation scope and purpose.
As a MySQL 8.4 example, a replica requests the source server’s binary log, stores it in a local relay log, and applies events independently. The log can record SQL statements (statement-based) or changed rows (row-based); the 8.4 manual says row-based logging is the default. This describes MySQL’s implementation and should not be generalized to other products. MySQL 8.4: Replication Implementation, Replication Formats
How is a replica different from a backup?
A replica can receive and apply an accidental deletion or an incorrect change from the source. So a replica may end up in the same bad state if a table is deleted by mistake or corrupted data is written. A backup preserves a copy for a point in time and serves a different purpose from replication. Production systems need access-controlled backups, retention periods, and restore exercises independently of replication. Even when a backup is created from a replica, verify that backup validation and recovery-point requirements are met.
What should you decide before rollout and monitor afterward?
**State the goal in one sentence.** Specify whether failure promotion, read distribution, or remote analytics is the priority. Do not assume one replication setup optimizes all three.
**Define consistency needs.** Set an acceptable read lag, the acknowledgement condition for a successful write, the data loss allowed during failover, and the recovery time.
**Design a single write path and recovery procedure.** Document who selects the primary, how the old primary is fenced, and the order for switching clients and replicas.
**Observe lag and capacity.** Monitor log generation, transfer and apply delay, replica replay position, replication-slot or log retention, connection state, free disk, and read latency. Metric names differ by product, so build dashboards from its administration documentation.
**Practice failures.** Test primary loss, network isolation, a lagging replica, and restoring an old backup; compare results with expected data-loss and recovery-time limits. Start in an isolated test environment where a check cannot trigger a production failover.
**Reassess write load and cost.** Replicas add load to ship write logs, network transfer, storage, observability, and on-call operations. Measure whether read-throughput gains justify these costs.
Database replication is a way to decide how multiple servers share changes. High availability also needs failure detection, fencing, and promotion; read scaling needs a freshness policy; remote distribution needs defined data scope and lag limits. Synchronous level trades possible data loss against commit latency. Define requirements as measurable limits and operational procedures before choosing a method.
Scope and sources
[PostgreSQL 18: High Availability, Load Balancing, and Replication](https://www.postgresql.org/docs/18/high-availability.html)
[PostgreSQL 18: Comparison of Different Solutions](https://www.postgresql.org/docs/18/different-replication-solutions.html)
[MySQL 8.4: Replication Implementation](https://dev.mysql.com/doc/refman/8.4/en/replication-implementation.html)
[MySQL 8.4: Replication Formats](https://dev.mysql.com/doc/refman/8.4/en/replication-formats.html)
Official documentation was checked on 2026-11-22. General concepts describe change propagation among database servers; product behavior is bounded to PostgreSQL 18 and MySQL 8.4. The diagram is a conceptual flow and does not specify a particular network or consistency implementation. No replication setup, performance test, or failover test was performed.