I would like to ask what is advisable when scaling out sharded cluster.
I am planning to scale out horizontally my sharded cluster(3 node cluster), and initially, the design is to add a new node. So now, there are 4 nodes in my cluster and each node should only have 3 mongodb shards. This is done by using pacemaker location constraints and max clone to limit 3 processes per shard in each node.
3-Node cluster
P - Primary
S - Secondary
Node 1: P - shard 1(Port: 27018), P - shard 2(Port: 27019), P - shard 3(Port: 27020)
Node 2: S -shard 1(Port: 27018, S -shard 2(Port: 27019), S -shard 3(Port: 27020)
Node 3: S -shard 1(Port: 27018, S -shard 2(Port: 27019), S -shard 3(Port: 27020)
Option 1:
Port number will increase dynamically.
4-node cluster
Node 1: P - shard 1(Port: 27018), P - shard 2(Port: 27019), P - shard 3(Port: 27020)
Node 2: S -shard 1(Port: 27018), S -shard 2(Port: 27019), S -shard 4(Port: 27021)
Node 3: S -shard 1(Port: 27018), S -shard 4(Port: 27021), S -shard 3(Port: 27020)
Node 4: P -shard 4(Port: 27021), S -shard 2(Port: 27019), S -shard 3(Port: 27020)
5-node cluster
Node 1: P - shard 1(Port: 27018), P - shard 2(Port: 27019), P - shard 3(Port: 27020)
Node 2: S -shard 1(Port: 27018), S -shard 2(Port: 27019), S -shard 4(Port: 27021)
Node 3: S -shard 1(Port: 27018), S -shard 4(Port: 27021), S -shard 5(Port: 27022)
Node 4: P -shard 4(Port: 27021), S -shard 5(Port: 27022), S -shard 3(Port: 27020)
Node 5: P -shard 5(Port: 27022), S -shard 2(Port: 27019), S -shard 3(Port: 27020)
Option 2:
Port number used is only 3.
4-node cluster
Node 1: P - shard 1(Port: 27018), P - shard 2(Port: 27019), P - shard 3(Port: 27020)
Node 2: S -shard 1(Port: 27018), S -shard 2(Port: 27019), S -shard 4(Port: 27020)
Node 3: S -shard 1(Port: 27018), S -shard 4(Port: 27019), S -shard 3(Port: 27020)
Node 4: P -shard 4(Port: 27018), S -shard 2(Port: 27019), S -shard 3(Port: 27020)
5-node cluster
Node 1: P - shard 1(Port: 27018), P - shard 2(Port: 27019), P - shard 3(Port: 27020)
Node 2: S -shard 1(Port: 27018), S -shard 2(Port: 27019), S -shard 4(Port: 27020)
Node 3: S -shard 1(Port: 27018), S -shard 4(Port: 27019), S -shard 5(Port: 27020)
Node 4: P -shard 4(Port: 27018), S -shard 5(Port: 27019), S -shard 3(Port: 27020)
Node 5: P -shard 5(Port: 27018), S -shard 2(Port: 27019), S -shard 3(Port: 27020)
Which is better, option 1 or option 2? Which is recommended?
For option 2, the issue will be adding of ports in the firewall. More shards that will be added, more ports will be added also in firewall setting.