1.

What is the role of balancer in a sharded cluster environment and how does it work?

Answer»

In MongoDB we can read from Primary as well as secondary members of the replica set. This behaviour can be controlled by us as we can define the desired Read preference to which clients route read operations to a member of the replica set. If we do not specify any real preference by default MongoDB will read from primary. There are situations when you would want to reduce the load on your primary by FORCING applications to read from secondary.

Below are DIFFERENT MongoDB read preference MODES:

  • primary

This is the default mode. Applications read from the replica set primary.  

  • primaryPreferred

In this mode, all applications read from primary but if the primary member is not AVAILABLE they start reading from secondary.

  • secondary

All applications read from the secondary members of the replica set.

  • secondaryPreferred

In this mode, all applications read from secondary but if any secondary member is not available they start reading from primary.

  • nearest

In this mode, applications read from the member which is nearest to them in terms of network latency, irrespective of the member being primary or secondary.



Discussion

No Comment Found