Backups, RPO and RTO
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
- 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.
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?
(a) Targets:
(b) Setup:
(c) Accidental deletion:(a) Targets:
- Transactions DB: RPO = 0 (no confirmed transaction lost), RTO = 15 minutes.
- Analytics DB: RPO = 24 hours, RTO = 24 hours.
(b) Setup:
- Transactions DB: synchronous standby in another availability zone with automatic
failover (covers RPO 0 / fast RTO for machine or zone failures); continuous WAL
archiving to object storage for point-in-time recovery; daily full snapshots;
backups copied to another region and account; regular restore tests.
- Analytics DB: nightly snapshot to object storage, kept for 14-30 days. It can
also be rebuilt from the source systems.
(c) Point-in-time recovery: restore the backup to a new instance at the moment just
before the DELETE, then copy the lost table back. Replicas won't help - they
deleted the table too. Also: restricted production access, reviewed migrations,
and delayed replicas or soft deletes for critical data.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.