Home CS Fundamentals Database Replication: Synchronous vs Asynchronous Explained
Advanced 4 min · July 13, 2026

Database Replication: Synchronous vs Asynchronous Explained

Learn the differences between synchronous and asynchronous database replication, their trade-offs, real-world use cases, and how to debug replication issues in production..

N
Naren Founder & Principal Engineer

20+ years shipping production systems from the metal up. Drawn from code that ran under real load.

Follow
Production
production tested
July 13, 2026
last updated
2,165
articles · all by Naren
Before you start⏱ 15-20 min read
  • Basic understanding of databases and SQL
  • Familiarity with ACID properties
  • Knowledge of database transactions
 ● Production Incident 🔎 Debug Guide ⚙ Triage Commands
Quick Answer

Synchronous replication ensures data consistency by requiring all replicas to acknowledge writes before committing, but increases latency. Asynchronous replication allows faster writes by not waiting for replicas, risking data loss on failure. Choose based on consistency vs performance needs.

✦ Definition~90s read
What is Database Replication?

Database replication is the process of copying data from a primary database to one or more replicas to ensure availability and scalability.

Think of synchronous replication like a group project where everyone must sign off before submitting—safe but slow.
Plain-English First

Think of synchronous replication like a group project where everyone must sign off before submitting—safe but slow. Asynchronous replication is like sending an email; you send it and assume it arrives, but sometimes it gets lost.

Imagine you're building a global e-commerce platform. Your database is the backbone, storing orders, inventory, and user data. If your primary database goes down, you lose everything. That's where replication comes in: you maintain copies of your data on multiple servers. But how do you keep those copies in sync? The answer lies in two strategies: synchronous and asynchronous replication. Synchronous replication waits for all copies to confirm a write before telling the client it's done, ensuring strong consistency but adding latency. Asynchronous replication lets the write complete immediately on the primary and propagates changes later, offering better performance but risking data loss. In this tutorial, we'll dive deep into both approaches, their trade-offs, real-world incidents, and how to debug replication issues in production.

What is Database Replication?

Database replication is the process of copying data from one database server (the primary) to one or more other servers (replicas). This ensures high availability, fault tolerance, and read scalability. Replication can be synchronous or asynchronous, affecting consistency and performance. In synchronous replication, the primary waits for all replicas to acknowledge a write before committing. In asynchronous replication, the primary commits immediately and sends changes to replicas later. The choice depends on your application's consistency requirements and latency tolerance.

setup_replication.sqlSQL
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
-- Example: Setting up MySQL asynchronous replication
-- On primary server:
CREATE USER 'repl'@'%' IDENTIFIED BY 'password';
GRANT REPLICATION SLAVE ON *.* TO 'repl'@'%';
FLUSH PRIVILEGES;
SHOW MASTER STATUS; -- note File and Position

-- On replica server:
CHANGE MASTER TO
  MASTER_HOST='primary_host',
  MASTER_USER='repl',
  MASTER_PASSWORD='password',
  MASTER_LOG_FILE='mysql-bin.000001',
  MASTER_LOG_POS=12345;
START SLAVE;
SHOW SLAVE STATUS\G
Output
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Seconds_Behind_Master: 0
🔥Replication Topologies
📊 Production Insight
Always monitor replication lag; a lag of seconds can cause stale reads in async setups.
🎯 Key Takeaway
Replication provides redundancy and scalability but introduces complexity in consistency.

Synchronous Replication: Strong Consistency at a Cost

In synchronous replication, the primary waits for all replicas to confirm that a write has been applied before acknowledging the client. This guarantees that all replicas have the same data at all times, providing strong consistency. However, this increases write latency because the slowest replica determines the response time. If a replica is down, the primary may block or fail the write. Synchronous replication is ideal for applications where data integrity is critical, such as financial transactions or inventory management. Common implementations include MySQL Group Replication, PostgreSQL synchronous replication, and Google Spanner.

sync_replication.sqlSQL
1
2
3
4
5
6
7
8
9
-- PostgreSQL synchronous replication setup
-- On primary: postgresql.conf
synchronous_standby_names = 'standby1, standby2'

-- On standby: recovery.conf
primary_conninfo = 'host=primary_host port=5432 user=repl password=password'

-- Check sync state on primary:
SELECT application_name, state, sync_state FROM pg_stat_replication;
Output
application_name | state | sync_state
------------------+-------+------------
standby1 | streaming | sync
standby2 | streaming | sync
⚠ Performance Impact
📊 Production Insight
If a synchronous replica fails, the primary may block writes until it recovers or is removed from the sync list.
🎯 Key Takeaway
Synchronous replication ensures zero data loss but sacrifices write performance.

Asynchronous Replication: Performance with Trade-offs

Asynchronous replication allows the primary to commit writes immediately without waiting for replicas. Changes are sent to replicas asynchronously, often via a binary log or write-ahead log. This results in low write latency and high throughput, but introduces a risk of data loss if the primary fails before changes are replicated. Replicas may lag behind, causing stale reads. Asynchronous replication is suitable for read-heavy applications, analytics, or geographical distribution where eventual consistency is acceptable. Examples include MySQL asynchronous replication, MongoDB replica sets, and Cassandra.

async_replication.sqlSQL
1
2
3
4
5
6
7
8
9
10
-- MySQL asynchronous replication status check
SHOW SLAVE STATUS\G
-- Key fields:
-- Slave_IO_Running: Yes
-- Slave_SQL_Running: Yes
-- Seconds_Behind_Master: 0 (ideal)

-- Simulate a write on primary:
INSERT INTO orders (id, product) VALUES (1, 'Laptop');
-- On replica, the insert appears after a short delay.
Output
Seconds_Behind_Master: 0
💡Monitoring Lag
📊 Production Insight
In a network partition, async replicas can fall far behind; always have a plan for failover and data reconciliation.
🎯 Key Takeaway
Asynchronous replication offers better performance but risks data loss and stale reads.

Semi-Synchronous Replication: A Middle Ground

Semi-synchronous replication is a compromise: the primary waits for at least one replica to acknowledge the write before committing. This reduces data loss risk while keeping latency lower than full synchronous replication. If no replica acknowledges within a timeout, the primary falls back to asynchronous mode. This is useful for applications that need better consistency than async but can tolerate some latency. MySQL and PostgreSQL support semi-synchronous replication.

semi_sync.sqlSQL
1
2
3
4
5
6
7
8
9
-- MySQL semi-synchronous replication setup
INSTALL PLUGIN rpl_semi_sync_master SONAME 'semisync_master.so';
SET GLOBAL rpl_semi_sync_master_enabled = 1;
SET GLOBAL rpl_semi_sync_master_timeout = 1000; -- 1 second timeout

-- On replica:
INSTALL PLUGIN rpl_semi_sync_slave SONAME 'semisync_slave.so';
SET GLOBAL rpl_semi_sync_slave_enabled = 1;
STOP SLAVE IO_THREAD; START SLAVE IO_THREAD;
Output
Query OK, 0 rows affected
🔥Timeout Behavior
📊 Production Insight
Semi-sync is a good default for many production systems; it provides a safety net without the full latency penalty.
🎯 Key Takeaway
Semi-sync balances consistency and performance by requiring at least one replica acknowledgment.

Choosing Between Synchronous and Asynchronous

The choice depends on your application's consistency requirements, latency tolerance, and network conditions. Use synchronous replication for critical data that cannot be lost (e.g., financial transactions). Use asynchronous replication for read-heavy workloads or when low write latency is paramount. Consider semi-synchronous as a balanced option. Also factor in geographical distance: synchronous replication over long distances can be very slow. In multi-region deployments, asynchronous replication is common, often with conflict resolution strategies.

decision.sqlSQL
1
2
3
4
5
6
-- Hypothetical decision query
SELECT CASE
  WHEN consistency_required = 'strong' AND latency_tolerance = 'low' THEN 'Synchronous'
  WHEN consistency_required = 'eventual' AND latency_tolerance = 'high' THEN 'Asynchronous'
  ELSE 'Semi-synchronous'
END AS replication_type;
Output
replication_type: Semi-synchronous
💡Hybrid Approaches
📊 Production Insight
Always test replication under load and simulate failures to understand behavior.
🎯 Key Takeaway
There is no one-size-fits-all; evaluate trade-offs based on your use case.

Monitoring and Troubleshooting Replication

Effective monitoring is crucial for replication health. Key metrics include replication lag, IO and SQL thread status, and error logs. Tools like MySQL's SHOW SLAVE STATUS, PostgreSQL's pg_stat_replication, and third-party solutions (e.g., Percona Monitoring and Management) help. Common issues: network latency, disk I/O bottlenecks, and data conflicts. For async replication, lag can spike during heavy writes. For sync, a slow replica can block writes. Always have a rollback plan.

monitor_replication.sqlSQL
1
2
3
4
5
6
7
8
9
-- MySQL replication monitoring queries
-- Check lag
SELECT TIMESTAMPDIFF(SECOND, last_seen, NOW()) AS lag_seconds
FROM information_schema.global_status
WHERE variable_name = 'Seconds_Behind_Master';

-- Check threads
SHOW PROCESSLIST;
-- Look for 'Binlog Dump' on primary and 'Slave_IO'/'Slave_SQL' on replica
Output
lag_seconds: 2
⚠ Common Pitfall
📊 Production Insight
Set up alerts for replication lag exceeding 10 seconds and for thread failures.
🎯 Key Takeaway
Proactive monitoring prevents data loss and performance degradation.

Advanced Topics: Multi-Master and Conflict Resolution

Multi-master replication allows multiple nodes to accept writes, increasing write scalability but introducing conflict resolution challenges. Synchronous multi-master (e.g., Galera Cluster) uses certification-based replication to avoid conflicts. Asynchronous multi-master (e.g., MySQL master-master) requires application-level conflict resolution or last-write-wins strategies. Conflict resolution can be based on timestamps, vector clocks, or custom logic. This is common in distributed databases like Cassandra and DynamoDB.

conflict_resolution.sqlSQL
1
2
3
4
5
6
-- Example: last-write-wins conflict resolution
-- Assume two masters insert same key
-- Master A: INSERT INTO users (id, name, updated_at) VALUES (1, 'Alice', '2025-01-01 10:00:00');
-- Master B: INSERT INTO users (id, name, updated_at) VALUES (1, 'Bob', '2025-01-01 10:00:01');
-- After replication, the later timestamp wins:
SELECT * FROM users WHERE id = 1; -- returns Bob
Output
id: 1, name: Bob, updated_at: 2025-01-01 10:00:01
🔥CRDTs
📊 Production Insight
Avoid multi-master with async unless you have robust conflict resolution; prefer single-master for simplicity.
🎯 Key Takeaway
Multi-master replication increases complexity; plan conflict resolution carefully.

Logical vs Physical Replication: PostgreSQL Comparison

In PostgreSQL, replication can be implemented at two levels: physical and logical. Physical replication operates at the block level, copying entire data files from primary to standby. It is simple, efficient, and supports all DDL changes automatically, but requires identical hardware and PostgreSQL versions. Logical replication, introduced in PostgreSQL 10, works at the row level using a publish-subscribe model. It allows selective replication of tables, cross-version replication, and even partial data filtering. However, logical replication does not replicate DDL changes automatically and may have higher overhead due to row-level decoding.

Consider a scenario where you need to replicate only a subset of tables to a reporting server. With logical replication, you can create a publication on the primary:

``sql CREATE PUBLICATION sales_pub FOR TABLE orders, customers; ``

``sql CREATE SUBSCRIPTION sales_sub CONNECTION 'host=primary dbname=mydb' PUBLICATION sales_pub; ``

Physical replication is ideal for full database failover with minimal latency, while logical replication excels in data distribution, upgrades, and multi-master setups. Choose based on your consistency and flexibility needs.

logical_replication_setup.sqlSQL
1
2
3
4
5
-- On primary server
CREATE PUBLICATION sales_pub FOR TABLE orders, customers;

-- On subscriber server
CREATE SUBSCRIPTION sales_sub CONNECTION 'host=primary dbname=mydb' PUBLICATION sales_pub;
🔥When to Use Logical Replication
📊 Production Insight
In production, use physical replication for synchronous failover and logical replication for asynchronous data distribution or zero-downtime upgrades. Monitor both for lag and conflicts.
🎯 Key Takeaway
Physical replication copies entire data blocks for simplicity and performance, while logical replication offers flexibility at the cost of some overhead and limitations.

Cascading Replication and Bi-Directional Replication

Cascading replication allows a standby server to act as a source for other standbys, reducing load on the primary. In PostgreSQL, physical cascading replication is straightforward: configure a standby to stream from another standby using the primary_conninfo parameter. For example, set up a cascading standby by pointing it to an intermediate standby:

``sql -- On cascading standby's postgresql.conf primary_conninfo = 'host=intermediate_standby port=5432 user=replicator password=secret' ``

Bi-directional replication (BDR) enables multiple nodes to accept writes and replicate changes to each other. This is more complex and often handled by extensions like BDR or using logical replication in a multi-master setup. For instance, with logical replication, you can create publications and subscriptions in both directions, but conflict resolution must be handled manually or via application logic.

Cascading replication is useful for geographically distributed architectures where you want to minimize direct connections to the primary. BDR is critical for active-active configurations but requires careful design to avoid data conflicts. Always test conflict resolution strategies in a staging environment.

cascading_replication_config.sqlSQL
1
2
3
4
5
6
7
8
9
10
11
-- On cascading standby's postgresql.conf
primary_conninfo = 'host=intermediate_standby port=5432 user=replicator password=secret'

-- For bi-directional logical replication, create publications on both nodes
-- Node A
CREATE PUBLICATION pub_a FOR TABLE t1;
CREATE SUBSCRIPTION sub_b CONNECTION 'host=node_b dbname=mydb' PUBLICATION pub_b;

-- Node B
CREATE PUBLICATION pub_b FOR TABLE t1;
CREATE SUBSCRIPTION sub_a CONNECTION 'host=node_a dbname=mydb' PUBLICATION pub_a;
⚠ Conflict Risks in Bi-Directional Replication
📊 Production Insight
Use cascading replication for read scalability in remote data centers. Avoid bi-directional replication unless absolutely necessary; prefer active-passive with failover for simplicity.
🎯 Key Takeaway
Cascading replication reduces primary load, while bi-directional replication enables multi-master writes but requires robust conflict handling.

Replication Monitoring: Lag, Conflicts, and Healing

Monitoring replication health is critical to ensure data consistency and availability. Key metrics include replication lag (time delay between primary and standby), conflicts (in logical replication), and automatic healing mechanisms.

```sql -- Check physical replication lag SELECT pg_size_pretty(pg_wal_lsn_diff(pg_current_wal_lsn(), replay_lsn)) AS lag_bytes, now() - pg_last_xact_replay_timestamp() AS lag_time FROM pg_stat_replication;

-- For logical replication, check subscription status SELECT subname, pg_stat_subscription.last_msg_receipt_time, pg_stat_subscription.latest_end_lsn FROM pg_stat_subscription; ```

Conflicts in logical replication occur when a replicated row violates a constraint (e.g., unique key) on the subscriber. PostgreSQL logs these errors and may skip the conflicting transaction. To detect conflicts, monitor the subscriber logs or use extensions like pglogical. Automatic healing involves retrying failed transactions or re-syncing tables via ALTER SUBSCRIPTION ... REFRESH PUBLICATION.

Set up alerting for lag exceeding thresholds (e.g., > 10 seconds) and implement automated failover with tools like Patroni. Regularly test failover procedures to ensure healing works as expected.

monitor_replication.sqlSQL
1
2
3
4
5
6
7
8
9
10
11
-- Physical replication lag
SELECT pg_size_pretty(pg_wal_lsn_diff(pg_current_wal_lsn(), replay_lsn)) AS lag_bytes,
       now() - pg_last_xact_replay_timestamp() AS lag_time
FROM pg_stat_replication;

-- Logical replication subscription status
SELECT subname, last_msg_receipt_time, latest_end_lsn
FROM pg_stat_subscription;

-- Check for replication conflicts in logs (example)
SELECT * FROM pg_stat_subscription WHERE last_msg_receipt_time < now() - interval '5 minutes';
💡Proactive Monitoring
📊 Production Insight
In production, implement a monitoring dashboard with lag metrics and conflict alerts. Use Patroni or similar for automated failover and healing. Test recovery procedures quarterly.
🎯 Key Takeaway
Monitor replication lag and conflicts using system views and logs. Automate healing with failover tools and periodic re-syncs to maintain data consistency.
● Production incidentPOST-MORTEMseverity: high

The Lost Order: An Asynchronous Replication Horror Story

Symptom
Customers reported missing orders after a brief network partition.
Assumption
The developer assumed asynchronous replication would eventually catch up without data loss.
Root cause
The primary database crashed before replicating a batch of writes; replicas were behind by 5 seconds.
Fix
Switched to semi-synchronous replication for critical order data and added monitoring for replication lag.
Key lesson
  • Asynchronous replication can lose data on primary failure.
  • Monitor replication lag with alerts.
  • Use semi-sync or sync for critical data.
  • Test failover scenarios regularly.
  • Design idempotent write operations.
Production debug guideSymptom to Action3 entries
Symptom · 01
Reads return stale data
Fix
Check replication lag using SHOW SLAVE STATUS; monitor seconds_behind_master.
Symptom · 02
Write timeouts on primary
Fix
Check if synchronous replication is causing high latency; consider reducing sync replicas or switching to async.
Symptom · 03
Replica out of sync
Fix
Use pt-table-checksum to identify differences; re-sync using pt-table-sync or rebuild replica.
★ Quick Debug Cheat SheetCommon replication issues and immediate actions.
High replication lag
Immediate action
Check network bandwidth and replica CPU
Commands
SHOW SLAVE STATUS\G
SHOW PROCESSLIST;
Fix now
Increase replica resources or reduce write load.
Replica SQL thread stopped+
Immediate action
Check for duplicate key or missing row errors
Commands
SHOW SLAVE STATUS\G
SHOW ENGINE INNODB STATUS\G
Fix now
Skip the problematic query or manually fix the data.
Primary crash after async write+
Immediate action
Promote most up-to-date replica
Commands
SHOW SLAVE STATUS\G
STOP SLAVE; RESET SLAVE ALL;
Fix now
Failover to replica and accept data loss.
FeatureSynchronousAsynchronousSemi-Synchronous
ConsistencyStrongEventualStrong (with timeout)
Write LatencyHighLowMedium
Data Loss RiskNonePossibleLow (if timeout not exceeded)
Read ScalabilityLimitedHighHigh
Network DependencyHighLowMedium
Use CaseFinancial transactionsAnalytics, logsE-commerce, critical data
⚙ Quick Reference
10 commands from this guide
FileCommand / CodePurpose
setup_replication.sqlCREATE USER 'repl'@'%' IDENTIFIED BY 'password';What is Database Replication?
sync_replication.sqlsynchronous_standby_names = 'standby1, standby2'Synchronous Replication
async_replication.sqlSHOW SLAVE STATUS\GAsynchronous Replication
semi_sync.sqlINSTALL PLUGIN rpl_semi_sync_master SONAME 'semisync_master.so';Semi-Synchronous Replication
decision.sqlSELECT CASEChoosing Between Synchronous and Asynchronous
monitor_replication.sqlSELECT TIMESTAMPDIFF(SECOND, last_seen, NOW()) AS lag_secondsMonitoring and Troubleshooting Replication
conflict_resolution.sqlSELECT * FROM users WHERE id = 1; -- returns BobAdvanced Topics
logical_replication_setup.sqlCREATE PUBLICATION sales_pub FOR TABLE orders, customers;Logical vs Physical Replication
cascading_replication_config.sqlprimary_conninfo = 'host=intermediate_standby port=5432 user=replicator password...Cascading Replication and Bi-Directional Replication
monitor_replication.sqlSELECT pg_size_pretty(pg_wal_lsn_diff(pg_current_wal_lsn(), replay_lsn)) AS lag_...Replication Monitoring

Key takeaways

1
Synchronous replication provides strong consistency but higher write latency.
2
Asynchronous replication offers better performance but risks data loss and stale reads.
3
Semi-synchronous replication balances consistency and performance.
4
Monitor replication lag and thread status to prevent issues.
5
Choose replication strategy based on data criticality and network conditions.

Common mistakes to avoid

3 patterns
×

Assuming async replication guarantees no data loss

×

Not monitoring replication lag

×

Using synchronous replication over long distances without considering latency

INTERVIEW PREP · PRACTICE MODE

Interview Questions on This Topic

Q01JUNIOR
Explain the difference between synchronous and asynchronous replication.
Q02SENIOR
How would you design a replication strategy for a global e-commerce plat...
Q03SENIOR
Describe a scenario where asynchronous replication could cause data inco...
Q01 of 03JUNIOR

Explain the difference between synchronous and asynchronous replication.

ANSWER
Synchronous replication requires all replicas to acknowledge a write before commit, ensuring strong consistency but higher latency. Asynchronous replication commits immediately and replicates later, offering better performance but potential data loss.
FAQ · 5 QUESTIONS

Frequently Asked Questions

01
What is the main difference between synchronous and asynchronous replication?
02
Can I mix synchronous and asynchronous replication in the same database?
03
What happens if a synchronous replica fails?
04
How do I measure replication lag?
05
Is asynchronous replication safe for financial data?
N
Naren Founder & Principal Engineer

20+ years shipping production systems from the metal up. Drawn from code that ran under real load.

Follow
Verified
production tested
July 13, 2026
last updated
2,165
articles · all by Naren
🔥

That's . Mark it forged?

4 min read · try the examples if you haven't

Previous
Database Sharding: Strategies and Patterns
1 / 1 ·
Next
SQL Query Optimization and Execution Plans