Home > OS >  Mongodb: availability vs consistency
Mongodb: availability vs consistency

Time:03-01

MongoDB follows master-slave architecture. Data is written in master node, which is then replicated to slave nodes. Mongo is said to provide consistency over availability, thinking about which, difference can be explained as:

When master goes down, slave nodes have to decide which one to pick as master which takes time and so system is unavailable for that time window.

Another reason can be: During replication, nodes are locked so that data is copied to all slaves for high consistency, and if we are using slaves for read then locking means unavailability.

But then this can vary as per configuration as Mongo allows to configure role of slaves. We can either have them just for replica purpose(in that case, slave locking may not be required as read requests are only served by master and replication can happen asynchronously) OR we can have slaves for read operations too(in that case, locking may be needed when writes happen so that consistency is there).

So I see there are many variations possible.

So do we have basic rules to define all this?

CodePudding user response:

MongoDB allow you to customize CAP-theorem behaviour depending on your use case requirements , you may adjust consistency/availability/performance via following settings :

read-preference possible values:

  ["primary","primaryPreferred","secondary","secondaryPreferred","nearest"]

write-concern possible values:

  ["majority",0,1,2,n]

read-concern possible values:

  ["local","available","majority","linearizable","snapshot"]

journaling possible values:

  ["true","false"]

In addition the question has been discussed previously in details here

  • Related