MongoDB Sharded Cluster Scaleout

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.

Hi @Ralph_Anthony_Plante,

In general I wouldn’t recommend multiple shards per host node unless you have a clear allocation of resources for each mongod process and have considered the potential consequences of failover scenarios (for example, making sure that your busiest primaries do not all end up on the same node). A 3 or 4 node replica set may be able to make more effective use of this hardware, but I assume you have done some comparison for your workload.

Since applications will be connecting to your cluster via mongos, the assignment of ports for shard servers should only affect administrators.

I think your Option 1 is less likely to lead to administrative confusion: it looks like shard 1 is always port 27018, shard 2 is always port 27019, etc. You can minimise firewall reconfiguration by allowing a larger port range with room for future expansion (eg 27018-27028).

Regards,
Stennie

1 Like