Replica sets
coreintermediateA replica set is a group of MongoDB servers holding the same data, so the loss of any one of them does not mean data loss or downtime. One member is the primary and accepts writes; the others are secondaries that continuously copy the primary's changes.
Think of it as
Think of it as several identical copies of the same database kept in sync automatically, with one designated as the current point of truth for writes at any given moment — and if that one disappears, the group elects a different member to take over the role, without anyone reconfiguring anything by hand.
What we're doing: Show why a lone standalone server is a single point of failure a replica set exists to remove.
- 2
- A standalone server has no automatic recovery path — its failure is the application's failure, and any unflushed data on that one disk is genuinely at risk.
- 6
- A replica set survives the same failure because the data already existed on other members before it happened, and the group can continue serving both reads and, after a short election, writes.
Why this works: The core value of a replica set is redundancy plus automatic recovery — the same data exists in more than one place, and the group can reorganize itself around a lost member without needing a human to intervene before service resumes.
- Application — sends writes
- leads to Primary (writes)
- Primary — accepts all writes
- leads to Secondary (oplog)
- leads to Secondary (oplog)
- Secondary — replicates from primary
- Secondary — replicates from primary
Running production MongoDB as a single standalone server "for now," planning to add replication later
Wrong
Better
What you see: The standalone server crashes or its disk fails, and there is no other copy of the data anywhere — a routine hardware failure becomes permanent data loss.
Why: A standalone server has no automatic recovery path at all, and converting one to a replica set later is more disruptive than starting as one — a replica set (even a single member, initially) costs nothing extra in normal operation and can grow into full redundancy without an application-visible migration.
Remember: A replica set is several servers holding the same data, one primary accepting writes at a time, with automatic election of a new primary if the current one becomes unreachable — this is MongoDB's baseline answer to "what happens when one server dies".
See also: primary and secondary members · election and failover

