- What is the difference between synchronous and asynchronous replication?
- Synchronous replication waits for at least one replica to confirm receipt before acknowledging a write — guaranteeing no data loss but adding latency. Asynchronous replication acknowledges immediately and replicates in the background — lower latency but potential data loss if the primary fails.
- What causes replication lag and how do I reduce it?
- Lag is caused by slow replica I/O, single-threaded SQL thread (MySQL < 5.6), large transactions, or network latency. Solutions: parallel replication (MySQL 8.0+, PostgreSQL), smaller transactions, dedicated replica hardware, and low-latency network between primary and replica.
- Should application code be aware of replica lag?
- For read-after-write consistency (reading your own writes immediately), always read from primary. For analytics and reporting queries that tolerate slightly stale data, replicas are appropriate. Session-level tracking of 'last write' position can route reads to a replica that is caught up to your write.