Do i need set priority for some members in shard cluster

Dear,
do i need set the priority for one of every shard replication set members, and let the one be the pirmary member when first startup?
say if i have five hosts A B C D E, and i have five shards,every shard is a replication set with two members.
host A:shard01_member0, shard05_member1
host B:shard02_member0, shard03_member1
host C:shard03_member0, shard04_member1
host D:shard04_member0, shard02_member1
host E:shard05_member0, shard01_member1

if i startup all mongod and mongos instance, then mongo will auto select the primary and secondary member for every replication set.
there is a situation that all five primary members are in hosts A,B,C .

is this the best practice that: set high priority for all member0 , then all member0 will be the primary member after first startup?

Hi @Yi_deng

every shard is a replication set with two members

Note that it’s not recommended to run a replica set with an even number of members, since electing a new Primary depends on having a majority vote. In this setup, if one of the node is offline, the remaining member will step itself down to become a read-only Secondary, since there are only 2 nodes in the set, and one of them is offline and thus cannot vote.

A minimum of three nodes is the recommended setup in a replica set. See Replica Set Deployment Architectures for more details.

is this the best practice that: set high priority for all member0 , then all member0 will be the primary member after first startup?

Not really. In a replica set, all members should be identical if they are to serve as the Primary or Secondaries (not counting any special-purpose nodes like analytics-only nodes, or the like). Thus, in a properly setup replica set, all nodes should be equally capable of taking over as Primary. In this case, since all nodes are equal, setting higher priority will serve little purpose due to: 1) It doesn’t really matter which of the identical nodes becomes Primary, and 2) Given the correct connection string, official MongoDB drivers will connect to all replica set members anyway.

If you’d like to find out more, you might want to consider checking out the free course M103 Basic Cluster Administration in MongoDB University. There are other free courses that should get you up to speed on different aspects of MongoDB as well if you’re interested.

Best regards
Kevin

1 Like

Dear kevin,
thanks for your help.
i still have the question:because client reads data from the primary members by default,
say my environment like this:
host A:shard01_member0, shard05_member1
host B:shard02_member0, shard03_member1
host C:shard03_member0, shard04_member1
host D:shard04_member0, shard02_member1
host E:shard05_member0, shard01_member1
there is a chance that all five primary members are in hosts A,B,C only.
then all the read pressure will be in hosts A,B,C only.

Having more than one member inside a single host is definitely not a recommended setup in a prod environment, as this is also mentioned in the Deploy a replica set: requirements. This is fine in a development environment, e.g. to test how the app will behave in failover events, but not in production, where (I believe) redundancy and high availability is important.

The main function of a replica set is to provide high availability and redundancy. Having multiple member of a replica set inside one host would eliminate all the benefits of a replica set. In fact, running multiple mongod inside one host is also not recommended, since this will create a resource contention and will slow things down.

Please check out the Production Notes for additional recommendations regarding deploying your own MongoDB servers.

Best regards
Kevin

2 Likes

Dear kevin
got it , thanks a lot.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.