Master-master vs master-slave database architecture?

Database

Database Problem Overview


I've heard about two kind of database architectures.

  • master-master

  • master-slave

Isn't the master-master more suitable for today's web cause it's like Git, every unit has the whole set of data and if one goes down, it doesn't quite matter.

Master-slave reminds me of SVN (which I don't like) where you have one central unit that handles thing.

Questions:

  1. What are the pros and cons of each?

  2. If you want to have a local database in your mobile phone like iPhone, which one is more appropriate?

  3. Is the choice of one of these a critical factor to consider thoroughly?

Database Solutions


Solution 1 - Database

While researching the various database architectures as well. I have compiled a good bit of information that might be relevant to someone else researching in the future. I came across

  1. Master-Slave Replication
  2. Master-Master Replication
  3. MySQL Cluster

I have decided to settle for using MySQL Cluster for my use case. However please see below for the various pros and cons that I have compiled

1. Master-Slave Replication

Pros

  • Analytic applications can read from the slave(s) without impacting the master
  • Backups of the entire database of relatively no impact on the master
  • Slaves can be taken offline and sync back to the master without any downtime

Cons

  • In the instance of a failure, a slave has to be promoted to master to take over its place. No automatic failover
  • Downtime and possibly loss of data when a master fails
  • All writes also have to be made to the master in a master-slave design
  • Each additional slave add some load to the master since the binary log have to be read and data copied to each slave
  • Application might have to be restarted

2. Master-Master Replication

Pros

  • Applications can read from both masters
  • Distributes write load across both master nodes
  • Simple, automatic and quick failover

Cons

  • Loosely consistent
  • Not as simple as master-slave to configure and deploy

3. MySQL Cluster

The new kid in town based on MySQL cluster design. MySQL cluster was developed with high availability and scalability in mind and is the ideal solution to be used for environments that require no downtime, high avalability and horizontal scalability.

See MySQL Cluster 101 for more information

Pros

  • (High Avalability) No single point of failure
  • Very high throughput
  • 99.99% uptime
  • Auto-Sharding
  • Real-Time Responsiveness
  • On-Line Operations (Schema changes etc)
  • Distributed writes

Cons

You can visit for my Blog full breakdown including architecture diagrams that goes into further details about the 3 mentioned architectures.

Solution 2 - Database

We're trading off availability, consistency and complexity. To address the last question first: Does this matter? Yes very much! The choices concerning how your data is to be managed is absolutely fundamental, and there's no "Best Practice" dodging the decisions. You need to understand your particular requirements.

There's a fundamental tension:

One copy: consistency is easy, but if it happens to be down everybody is out of the water, and if people are remote then may pay horrid communication costs. Bring portable devices, which may need to operate disconnected, into the picture and one copy won't cut it.

Master Slave: consistency is not too difficult because each piece of data has exactly one owning master. But then what do you do if you can't see that master, some kind of postponed work is needed.

Master-Master: well if you can make it work then it seems to offer everything, no single point of failure, everyone can work all the time. The trouble with this is that it is very hard to preserve absolute consistency. See the wikipedia article for more.

Wikipedia seems to have a nice summary of the advantages and disadvantages

> Advantages > > * If one master fails, other masters will continue to update the > database.

> * Masters can be located in several physical sites i.e. > distributed across the network. > > Disadvantages > > * Most multi-master replication systems are only loosely consistent, > i.e. lazy and asynchronous, violating ACID properties. >
> * Eager replication systems are complex and introduce some > communication latency. > > * Issues such as conflict resolution can become intractable as > the number of nodes involved rises and the required latency decreases.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionnever_had_a_nameView Question on Stackoverflow
Solution 1 - DatabaseSkillachieView Answer on Stackoverflow
Solution 2 - DatabasedjnaView Answer on Stackoverflow