Replication & Backups

Difficulty
Importance

The problem

A database living on one machine is one hardware failure away from total data loss, and one accidental bad query away from unrecoverable damage — replication protects against the machine failing, and backups protect against the data itself being wrong or deleted.

Why now

Transactions and ACID already established durability as a guarantee for a single machine; replication and backups are what extend that guarantee past a single machine's failure, and file systems and I/O already covered the durable storage mechanism backups fundamentally rely on.

Mental model

Replication keeps a live, continuously updated copy of the database on another machine, so if the primary dies, a replica can take over quickly — it protects against hardware failure, not against bad data, because a mistake gets replicated too. A backup is a frozen snapshot from a point in time, slower to restore from but the only real protection against corrupted or accidentally deleted data, since a bad write hasn't reached an old backup yet.

Requires

Unlocks

Used in

Projects

  • Set up a primary-replica database pair locally, write to the primary, and confirm the write propagates to the replica
  • Simulate an accidental bad DELETE query, then restore the database to a point before it happened using a backup

Examples

  • A replica can fail over to become the new primary within seconds of a hardware failure, minimizing downtime
  • An accidental DROP TABLE replicates to every replica almost instantly — only a backup taken before the mistake can undo it

Resources

Mastery checklist