Lesson 20 / 23

Replication & Replica Sets

Keep data available with replica sets, primary and secondary nodes, automatic failover and replication lag.

What is a replica set?

A replica set is a group of mongod servers holding the same data — one primary takes writes, and secondaries copy them.

Why replicate?

It gives high availability (a secondary is promoted automatically if the primary fails), redundancy, and optionally lets reads scale across secondaries.

Writes go to the primary

By default all writes target the primary node — reading from secondaries can return slightly stale data due to replication lag.