Part 7 · Reliability & Resilience

Backups & Disaster Recovery: RPO vs RTO

Replication faithfully copies a mistaken DELETE, ransomware or silent corruption to every replica in milliseconds. Why backups are a different thing, how RPO and RTO drive every decision, point-in-time recovery, the 3-2-1 rule, the four DR strategies, and why an untested backup is only a hope.

Lesson 458 min readintermediate#reliability#dr

On this page

  1. The Problem
  2. The Core Idea
  3. How It Works
  4. Trade-offs
  5. In the Real World
  6. Interview Questions
  7. Key Takeaways
  8. Further Reading

The Problem

You have done everything in this part: replicas (live copies of the database) in three zones, automatic failover, circuit breakers, load shedding. Then something like this happens:

  • an engineer runs DELETE FROM orders without a WHERE clause on production. (Without WHERE, the command deletes every row. "Production" is the live system that real users use.)
  • or ransomware (a program that locks your files and asks for money) encrypts your database servers,
  • or a software bug silently corrupts (damages) customer records for two weeks,
  • or a fire destroys the data centre (the building that holds your servers).

Replication does not help with any of these (except the fire, if the copies are in another place). Replication means keeping live copies of data on several servers. It copies the deletion, the encryption or the corruption to every replica within milliseconds. Your "highly available" system now has three perfect copies of the wrong data.

A backup is a separate copy of data from an earlier moment, kept so you can restore it. Disaster recovery (DR) is the plan and the setup for getting your system working again after a big failure. Both exist for exactly these cases. Two numbers drive every decision: RPO and RTO.

The Core Idea

Think about your phone's photos.

  • Replication is like having your photos synced between your phone and tablet. If your phone breaks, the tablet still has them. But if you delete an album on your phone, it is deleted on the tablet too.
  • A backup is like a separate copy on an external drive or in cloud storage, taken last Sunday. If you delete an album by mistake, you can go back to Sunday's copy.
  • Disaster recovery is your plan for getting back to normal. It says where the backups are, how to restore them, how long it takes, and who does it.

Two questions shape the plan:

  • RPO (Recovery Point Objective): "How much data can we afford to lose?" It is measured in time. If you back up every Sunday and lose your phone on Saturday, you lose almost a week of photos.
  • RTO (Recovery Time Objective): "How long can we afford to be down?" It is also measured in time. How long does it take to get a new phone and restore everything?

How It Works

RPO and RTO

  1. 02:00
    last good backup or copy
  2. 02:00 → 10:42
    everything written here may be lost — this gap is the RPO
  3. 10:42
    disaster: DELETE FROM orders with no WHERE
  4. 10:42 → 11:30
    down while restoring — this gap is the RTO
  5. 11:30
    service restored
RPO looks backwards from the disaster; RTO looks forwards. · timeline
  • RPO is measured backwards from the disaster. It is the most data loss you accept, shown as a length of time.
    • RPO = 24 hours: daily backups are enough.
    • RPO = 5 minutes: you need continuous log shipping (sending the database's change log to another place all the time) or replication.
    • RPO ≈ 0: you need synchronous replication, where a write counts as done only after the copy has it (and you still need backups for logical errors, which means human or software mistakes).
  • RTO is measured forwards from the disaster. It is the longest downtime you accept.
    • RTO = 1 day: restoring from backups onto new servers is fine.
    • RTO = 15 minutes: you need a warm standby (a smaller copy that is already running) ready to take over.
    • RTO ≈ 0: you need active-active across regions (all copies serve traffic all the time).

A lower RPO and RTO cost more money and add more complexity. Set them for each system, based on the harm to the business:

SystemExample RPOExample RTO
Payments / ledger~0 (no lost transactions)Minutes
OrdersMinutes< 1 hour
Product catalogueHours (can re-import)Hours
Analytics warehouse1 day1–2 days
Internal wiki1 day1 day

Replication is not a backup

ReplicationBackup
PurposeAvailability: survive the failure of a machine or zoneRecovery: go back in time
Protects against hardware failure✅✅ (slower)
Protects against accidental delete / bad migration❌ (copied instantly)✅
Protects against corruption / ransomware❌✅ (if isolated and immutable, which means kept apart and never changeable)
Time to recoverSeconds–minutesMinutes–hours+

You need both. Replication keeps the system running. Backups let you go back to an earlier time.

Types of backups

  • Full backup: a complete copy of everything. It is simple to restore, but slow to make and large.
  • Incremental backup: only what changed since the last backup (of any kind). It is small and fast to make. But to restore you need the full backup plus every incremental in the chain.
  • Differential backup: everything that changed since the last full backup. To restore you need the full backup plus the latest differential. (Difference in one line: incremental looks back to the last backup of any kind, differential looks back to the last full one.)
  • Snapshots: copies of a disk or volume at one moment (cloud disk snapshots, file-system snapshots). They are fast. For databases, check that they are consistent, which means the data is not caught half-written. Use the database's own backup tools, or pause writes for a moment.
  • Logical backups: exports of the data as SQL or another format (like pg_dump). They are portable and good for small databases or single tables, but slow for large ones.
  • Physical backups: copies of the database's own files (like pg_basebackup). They are fast for large databases.

Point-in-time recovery (PITR)

Point-in-time recovery (PITR) means restoring a database to an exact moment. Databases write every change to their write-ahead log first (WAL, post 21). The WAL is a record of all changes, in order. If you keep:

  1. a base backup (say, nightly), plus
  2. every WAL file since then (continuous archiving, often to object storage, a service for storing files),

then you restore the base backup and replay the WAL (apply the changes again, in order). You can stop at any moment, for example 10:41:59, one second before the bad DELETE ran.

  1. Base backup
    02:00
  2. + WAL replayed
    up to 10:41:59
  3. Database
    one second before the mistake
Point-in-time recovery: a base backup plus the archived write-ahead log. · flow

PITR gives a very low RPO for logical mistakes. Managed databases (Amazon RDS, Cloud SQL, Azure Database) offer it with a few clicks. You can only go back as far as the retention window (how long data is kept). The window is set by you, often between 1 and 35 days, and the limits differ between services.

The 3-2-1 rule (and beyond)

A classic rule for safe backups is called 3-2-1:

  • 3 copies of your data (the original plus 2 backups),
  • on 2 different types of storage or media,
  • with 1 copy off-site (in another place, such as another region or another provider).

Modern additions, especially because of ransomware:

  • Immutable backups: backups that cannot be changed or deleted for a set time, even by administrators. Example: the object lock feature in S3-compatible storage.
  • Isolated or "air-gapped" backups: kept in a separate account with different logins (air gapped originally meant not connected to any network). An attacker who breaks into production then cannot delete the backups too.
  • Encrypted backups (scrambled so only key holders can read them), with the keys managed carefully (Part 9). A backup that you cannot decrypt is useless.
3
copies
the original + 2 backups
2
kinds of storage
so one kind of failure cannot take both
1
off-site
another region or provider
+
immutable & isolated
object lock, separate account and credentials
The 3-2-1 rule, plus the modern additions ransomware made necessary. · numbers

Other protective habits

  • Soft deletes: mark rows as deleted (with a deleted_at column) instead of removing them at once, so they are easy to undo.
  • Delayed replicas: a replica that stays, on purpose, about 1 hour behind. If a bad change happens, you can stop the replica before the change reaches it, and recover quickly.
  • Audit logs: a record of who changed what and when, so you know what to restore.
  • Safe migrations (changes to the database structure): scripts that are reviewed and tested, a backup taken right before a risky change, and limited direct access to production.

Disaster recovery strategies

AWS describes four common DR strategies. They go from cheapest and slowest to most expensive and fastest. A region is a cloud area, and a standby is a spare copy:

Backup & restore
  • •Backups in another region; rebuild when needed
  • •RPO hours · RTO hours to days
Use whenInternal tools, analytics
Pilot light
  • •Core pieces (a DB replica) running; the rest off
  • •RPO minutes · RTO tens of minutes
Use whenImportant but not instant
Warm standby
  • •A scaled-down full copy running
  • •RPO seconds–minutes · RTO minutes
Use whenOrders, core APIs
Multi-site active-active
  • •Two or more regions serving traffic
  • •RPO ~0 · RTO ~0–minutes
Use whenPayments, ledgers — at the highest cost
The four disaster-recovery strategies, cheapest and slowest first. · compare

Infrastructure as code means describing your servers and networks in code files. Tools are Terraform, CloudFormation and Pulumi. It makes the cheaper strategies much faster, because you can rebuild whole environments from code and not from memory.

Test your restores

A backup that you have never restored is not a backup. It is only a hope. These are common failures that people find only during a real emergency:

  • backups were silently failing for months,
  • backups were empty, partial or corrupted,
  • the restore takes 12 hours, far beyond the RTO,
  • nobody knows the steps, or the only person who does is not available,
  • the encryption keys or logins needed to restore are missing,
  • the backup is fine, but the app cannot start because other pieces are missing (secrets, DNS, settings).

Good habits:

  • automatic restore tests. For example, restore last night's backup to a test environment every day and run checks on it,
  • regular DR drills: really switch to the DR region, or rebuild from backups, and measure how long it takes,
  • monitor backups: send an alert for failed or missing backups, and for backups that are smaller than expected,
  • written runbooks (step-by-step guides), updated after every drill.

Trade-offs

  • Lower RPO: less data is lost, but you need more frequent backups or continuous replication, and it costs more.
  • Lower RTO: faster recovery, but standby systems must run all the time, and it is more complex.
  • Multi-site active-active: almost no downtime, but the highest cost, and hard problems with keeping data consistent (posts 24, 27–28).
  • Long retention: you can recover from old corruption, but it costs more storage. There are also privacy and legal rules (compliance) about keeping personal data for a long time.
  • Immutable, isolated backups: strong protection from ransomware and mistakes, but you must manage accounts, keys and lifecycle rules (rules for how long to keep data) with more care.

In the Real World

GitLab (2017). During a stressful incident, an engineer accidentally deleted data from GitLab's primary production database. The team then found that several of their backup methods were not working as expected. They finally restored from a copy that was about six hours old, so some data was lost. GitLab live-streamed the recovery and published a very open postmortem (a report written after an incident). It is now a classic lesson: test your backups and restores.

The OVHcloud data-centre fire (2021). A fire destroyed one of OVHcloud's data centres in Strasbourg, France, and damaged another. Customers whose backups were kept in the same place as their servers lost data for good. Customers with off-site backups could recover. It shows the 3-2-1 rule in the hardest way.

Code Spaces (2014). An attacker got into the company's cloud account and deleted its servers, data and backups, which were all in the same account. The company shut down. This is why modern advice insists on isolated, immutable backups with separate logins.

Pixar and Toy Story 2. In a famous story, a wrong command started deleting the files for Toy Story 2 while the film was being made, and the backups turned out to be faulty. The film was saved because a technical director had a copy on her home computer. It was a lucky off-site backup, and a reminder not to count on luck.

Managed database PITR. Cloud database services make point-in-time recovery a standard feature. Many teams have recovered from accidental deletes. They restored a copy of the database to "five minutes before the mistake" and then copied back only the affected rows.

Interview Questions

Q1Why isn't replication a backup?

Replication copies every change to every replica within milliseconds. This includes accidental deletes, bad migrations, corruption and ransomware encryption. It protects against hardware and zone failure, but not against logical mistakes. Only a backup lets you go back in time.

Q2Define RPO and RTO.

RPO (recovery point objective) is the most data loss you accept, measured backwards from the disaster. RTO (recovery time objective) is the longest downtime you accept, until the service is back. Lower values need more frequent backups or replication, and standby capacity.

Q3How does point-in-time recovery work?

Take base backups on a schedule and keep archiving the write-ahead log all the time. To recover, restore the base backup and replay the WAL up to a chosen moment, for example one second before the bad statement ran.

Q4How do you protect backups from ransomware?

Store them as immutable (object lock or WORM, which means write once, read many) in a separate, isolated account with different logins. Encrypt them with carefully managed keys and keep a copy off-site. Then an attacker who controls production cannot delete or encrypt them too.

Q5How do you know your backups work?

Restore them, automatically and regularly. For example, restore last night's backup into a test environment every day and run checks. Send alerts for missing, failed or suspiciously small backups. Time full DR drills and compare with your RTO.

Q6Which DR strategy would you choose for a payments ledger?

Aim for an RPO close to zero and an RTO of minutes. Use synchronous or near-synchronous replication across zones, and a warm standby or active-active in another region. Add point-in-time backups for logical errors, and run failover drills regularly.

Key Takeaways

  • Replication ≠ backup. Replicas copy mistakes, corruption and ransomware instantly. You need backups to go back in time.
  • RPO = how much data you can lose. RTO = how long you can be down. Set both per system, based on business impact.
  • Use full, incremental and differential backups, snapshots, and point-in-time recovery (base backup + archived WAL).
  • Follow 3-2-1, plus immutable and isolated backups and careful key management. Add soft deletes, delayed replicas and audit logs.
  • Pick a DR strategy (backup & restore → pilot light → warm standby → active-active) to match your RPO/RTO, and test restores and failovers regularly.

Further Reading

  • The AWS whitepaper "Disaster Recovery of Workloads on AWS: Recovery in the Cloud"
  • Site Reliability Engineering by Google (chapter "Data Integrity: What You Read Is What You Wrote")
  • The PostgreSQL documentation chapter "Continuous Archiving and Point-in-Time Recovery (PITR)"
  • GitLab's public postmortem of its January 31, 2017 database outage
  • Microsoft Azure's reliability and business continuity documentation

This wraps up Part 7. Next up, Part 8: Observability, starting with "Logs, Metrics & Traces: The Three Pillars".

Published by Jainik · Last updated · How these lessons are made

Keep learning

Related series