When deploying MongoDB replica sets, there appears to be conflicting information in the official documentation regarding minimum member requirements. The deployment tutorial states:
"A replica set requires three distinct systems..."
While the core replication documentation mentions:
"Most replica sets consist of two or more mongod instances..."
In production environments, three members are indeed required for a proper replica set with:
- 1 Primary node
- 1 Secondary node
- 1 Arbiter (or another secondary for fault tolerance)
However, MongoDB technically allows temporary two-member configurations for development/testing purposes:
// Example of a 2-member replica set (DEV ONLY)
rs.initiate({
_id: "rs0",
members: [
{ _id: 0, host: "mongodb0.example.net:27017" },
{ _id: 1, host: "mongodb1.example.net:27017" }
]
})
Production: Always use odd number of members (3,5,7) for:
- Automatic failover
- Data redundancy
- Proper election consensus
Development: Two members can work temporarily but with limitations:
- No automatic failover (requires manual intervention)
- Vulnerable to split-brain scenarios
- Not recommended beyond basic testing
Here's a proper 3-member configuration:
// Production-grade replica set configuration
rs.initiate({
_id: "rsProd",
members: [
{ _id: 0, host: "mongo1.prod.net:27017" },
{ _id: 1, host: "mongo2.prod.net:27017" },
{ _id: 2, host: "mongo3.prod.net:27017", arbiterOnly: true }
],
settings: {
chainingAllowed: false,
heartbeatTimeoutSecs: 10,
electionTimeoutMillis: 10000
}
})
When planning your topology:
- Never deploy single-node "replica sets" - they defeat the purpose
- Two-member sets can work temporarily during maintenance
- For cloud deployments, consider using 3 data-bearing nodes instead of arbiters
- Network partitions require majority to maintain primary
For absolute clarity: 3 members is the minimum for production, while 2 members is technically possible but comes with significant operational risks.
The MongoDB documentation contains two seemingly conflicting statements regarding replica set minimum members:
- Deployment tutorial states: "A replica set requires three distinct systems"
- Core replication documentation states: "Most replica sets consist of two or more mongod instances"
Both statements are technically correct but serve different purposes:
// Minimum production configuration (recommended)
rs.initiate({
_id: "rs0",
members: [
{ _id: 0, host: "mongodb0.example.net:27017" },
{ _id: 1, host: "mongodb1.example.net:27017" },
{ _id: 2, host: "mongodb2.example.net:27017" }
]
})
While possible for development, a 2-member set has critical constraints:
- No automatic failover (requires arbiter for election quorum)
- Vulnerable to split-brain scenarios
- Violates CAP theorem's partition tolerance
The 3-member configuration provides:
// Safe primary election behavior
rs.conf().members = [
{ _id: 0, host: "primary.example.com:27017", priority: 2 },
{ _id: 1, host: "secondary1.example.com:27017", priority: 1 },
{ _id: 2, host: "secondary2.example.com:27017", priority: 1, arbiterOnly: true }
]
For resource-constrained environments:
- Two data-bearing members + one arbiter (lightweight)
- Two members + delayed secondary for disaster recovery
Always use three members in production:
// Docker compose example for local testing
version: '3'
services:
mongo1:
image: mongo
command: mongod --replSet rs0 --port 27017
mongo2:
image: mongo
command: mongod --replSet rs0 --port 27018
mongo3:
image: mongo
command: mongod --replSet rs0 --port 27019