Question: What is the minimum number of nodes required for a MongoDB cluster?

Answer

In a MongoDB deployment, the minimum number of nodes required can vary depending on the type of cluster you are setting up. There are primarily two types of clusters in MongoDB: Replica Sets and Sharded Clusters.

Replica Sets

For a Replica Set, which provides redundancy and high availability, the minimum recommended configuration is three nodes. This setup includes one primary node that handles all write operations and two secondary nodes that replicate the primary's data set, providing automated failover and read scaling.

rs.initiate( { _id : "myReplicaSet", members: [ { _id: 0, host: "mongodb0.example.net:27017" }, { _id: 1, host: "mongodb1.example.net:27017" }, { _id: 2, host: "mongodb2.example.net:27017" } ] })

However, it is technically possible to create a Replica Set with a single node for testing or development purposes by configuring the --replSet option when starting the MongoDB server. Keep in mind that such a configuration does not provide the benefits of redundancy or failover.

Sharded Clusters

For a Sharded Cluster, which distributes data across multiple machines, the minimum setup involves several components including:

  • At least two shard nodes (or replica sets for production environments, each shard being a replica set enhances data availability and failover capability).
  • At least one config server replica set, which requires a minimum of three nodes to ensure redundancy and high availability.
  • At least one mongos query router to interface with your application.

A minimal sharded cluster, therefore, would consist of at least six nodes: three config server nodes forming a replica set, plus a single shard composed of a three-node replica set. However, a typical production sharded cluster has many more nodes for increased capacity and fault tolerance.

In summary, the absolute minimum for a functioning MongoDB cluster varies by the type: a single node can technically form a Replica Set for non-production use, while a minimal sharded cluster for production should have at least six nodes. For most production deployments, significantly more nodes will be involved to ensure durability, fault tolerance, and performance.

Was this content helpful?

Start building today

Dragonfly is fully compatible with the Redis ecosystem and requires no code changes to implement.