Backups, RPO and RTO

Topic 10 of 10 in Week 3: Databases9 min readIntermediateFree course

Overview

Replication keeps a system running when a machine dies, but it faithfully copies every mistake: a bad migration, a buggy deploy that corrupts rows, an attacker who encrypts your data. Backups are the separate, older copies that let you go back in time. This lesson covers the kinds of backup, and two numbers that decide how much you need: RPO and RTO.

RPO and RTO

RPO and RTO on a timeline. After the last backup, a disaster happens, and later the service is back. The time between the last backup and the disaster is the RPO window: data written there is lost. The time between the disaster and recovery is the RTO: users are down. Typical values: a nightly backup restored by hand gives an RPO of up to 24 hours and an RTO of hours; continuous point-in-time backup gives an RPO of seconds to minutes and an RTO under an hour; a standby replica with automatic failover gives an RPO of zero to seconds and an RTO of seconds to minutes.

  • Recovery point objective (RPO): the maximum amount of data, measured in time, you can afford to lose. RPO of one hour means losing up to the last hour of writes is acceptable.
  • Recovery time objective (RTO): the maximum time the service can be down while you recover.

They’re business decisions with costs. RPO near zero needs synchronous replication; RTO of seconds needs automatic failover and standby capacity. A payments ledger and an internal analytics database rightly have very different targets.

Kinds of backup

  • Full backup: a complete copy, such as a database dump or a storage snapshot. Simple to restore, slow and large to take.
  • Incremental backup: only what changed since the last backup. Small and fast to take; restoring needs the full backup plus every increment.
  • Differential backup: everything changed since the last full backup. A middle ground.
  • Continuous log archiving: ship the database’s write-ahead log (or binlog) to durable storage as it’s written. Combined with a full backup, it allows point-in-time recovery (PITR): restore to any moment, such as 14:32:05, just before the bad DELETE.

Managed databases (Amazon RDS, Cloud SQL, Azure Database) offer automated snapshots plus PITR within a retention window, typically 7–35 days.

Logical vs physical

  • Logical backups (pg_dump, mysqldump) export data as SQL or another format. Portable and good for single tables, but slow for big databases.
  • Physical backups copy the data files or disk snapshots. Fast for large databases, but tied to the database version and layout.

Where to keep backups

The 3-2-1 rule: keep at least 3 copies of data, on 2 different kinds of storage, with 1 copy off-site (another region, ideally another account). Modern additions:

  • Immutable backups: object-lock or write-once storage that even an administrator (or attacker with admin credentials) can’t delete before the retention period ends. This is the main defence against ransomware.
  • Encryption of backups at rest, with keys managed separately.
  • Retention policy: for example hourly for two days, daily for a month, monthly for a year, plus any legal requirements.

Test your restores

Many teams discover during an incident that backups were incomplete, corrupted or take twelve hours to restore. Good practice:

  • restore automatically on a schedule into a scratch environment and check the data,
  • measure how long the restore takes and compare it with the RTO,
  • write and rehearse the runbook.

Beyond databases

Back up everything you’d need to rebuild: object storage (enable versioning and cross-region replication), configuration, secrets, infrastructure-as-code, and data in third-party SaaS tools. Data that can be fully regenerated (caches, search indexes, derived tables) may not need backups, only a documented way to rebuild it.

In an interview

For a system holding important data, add a sentence: “The database has a synchronous standby for failover, continuous WAL archiving for point-in-time recovery with 30-day retention, and daily snapshots copied to another region with object lock. RPO is effectively zero for node failures and a few minutes for disasters; RTO is under 30 minutes.” Disaster recovery across regions is covered in week 6.

Recap

Replication protects availability; backups protect against mistakes, corruption and attacks. Set RPO (how much data you can lose) and RTO (how long you can be down) with the business, then combine full backups, incremental or continuous log archiving and point-in-time recovery to meet them. Keep copies off-site and immutable, and test restores regularly.

Exercise

Set targets and a backup plan

A small fintech app stores customer accounts and transactions in PostgreSQL. The business says: 'We can never lose a confirmed transaction, and we can be down for at most 15 minutes.' A separate analytics database can lose up to a day of data and be down for a day. (a) Write the RPO and RTO for each. (b) Describe the backup and replication setup for each. (c) How would you protect against an engineer accidentally deleting a table in production?

Text
(a) Targets:
(b) Setup:
(c) Accidental deletion:

Summary

  • Backups protect against mistakes, corruption and attacks; replication alone copies mistakes instantly.
  • RPO (recovery point objective) is how much recent data you can afford to lose; RTO (recovery time objective) is how long you can be down.
  • Full, incremental and continuous (WAL/log) backups combine into point-in-time recovery.
  • Follow 3-2-1: three copies, two kinds of storage, one off-site — and keep some backups immutable.
  • A backup you haven't restored is a hope, not a backup: test restores regularly and time them.