Copy data across nodes for durability and read-scaling.
Data Flow (master-slave)
Master
|
v (async log shipping)
+--------+--------+--------+
|slave_0|slave_1|slave_2| (read replicas)
+--------+--------+--------+
Two flavours
- Master-slave: writes hit master; slaves serve reads. Replication lag = delay before slaves see the write.
- Multi-master: writes accepted at any node; must resolve conflicts (CRDTs, last-writer-wins, vector clocks).
Pitfalls
- Stale read: a write is followed immediately by a read on a slave that hasn’t caught up.
- Split brain in multi-master during a network partition -> two nodes both think they’re authoritative.
Mitigation
- Read-your-writes consistency: route the session’s own writes to the master for some time window.
- Quorum reads:
R + W > N (with N replicas, R reads, W writes).
Analogy
A library where the original book is at HQ and branches hold photocopies: branches lag behind HQ by a few hours.
Interview tip: Mention replication lag explicitly; it’s the cause of half the “data loss” production incidents.