HomeMYSQLDifference between master-slave and master-master replication?

Difference between master-slave and master-master replication?

Here’s a clear comparison of Master-Slave vs Master-Master replication in MySQL:


πŸ”Ή Master-Slave Replication

  • Definition: One server (master) handles all write operations, and the other server(s) (slaves) replicate data from the master.
  • Writes: Only allowed on the master.
  • Reads: Usually performed on slaves to reduce load on the master.
  • Use Case: Load balancing (read scaling), backups, reporting.
  • Failover: If the master fails, a slave needs to be promoted manually (or via automation) to act as master.
  • Data Flow: One-directional (Master ➝ Slave).
  • Conflict Handling: No conflict (since only master handles writes).

πŸ”Ή Master-Master Replication

  • Definition: Two (or more) servers act as masters, and replicate data to each other.
  • Writes: Can be performed on both masters.
  • Reads: Can be done on both masters (or additional slaves).
  • Use Case: High availability, failover without downtime, distributed writes.
  • Failover: Easier, because if one master goes down, the other can take over immediately.
  • Data Flow: Bi-directional (Master ⇆ Master).
  • Conflict Handling: Possible conflicts if the same row is updated on both masters at the same time (requires conflict resolution strategies).

πŸ”‘ Key Differences Table

FeatureMaster-Slave ReplicationMaster-Master Replication
WritesOnly on MasterOn both Masters
ReadsMainly on SlavesOn both Masters (and slaves)
Replication DirectionOne-way (β†’)Two-way (⇆)
FailoverManual / semi-automaticAutomatic / seamless
Conflict RiskNoneHigh (requires resolution)
Use CaseRead scaling, backupsHigh availability, HA failover

πŸ‘‰ In short:

  • Master-Slave = simpler, safe, mainly for read-heavy systems.
  • Master-Master = more complex, better for high availability and distributed writes, but needs careful conflict handling.

Share:Β 

No comments yet! You be the first to comment.

Leave a Reply

Your email address will not be published. Required fields are marked *