System designDeep dive11 min

Disaster recovery & backups

Redundancy keeps a service running when a machine, a zone or a region fails. Disaster recovery is for the failures redundancy copies faithfully: a deleted table, a corrupting bug, ransomware, a fire that takes the backups with it. It is decided by two numbers, how much data you may lose and how long you may be down, and proven only by restoring.

1 · The problem

Most disasters are mistakes that replication copies everywhere

A payroll service pays the staff of 40,000 small businesses. Its database has a synchronous standby in a second zone and an asynchronous replica in another region. It survives a dead server, a dead zone, even a dead region. Then, at 14:00 on the 27th, a migration with a bug in its WHERE clause sets every employee's bank account to the same value. Within a second the standby and the remote replica have faithfully copied the damage.

Redundancy protects against copies disappearing. It does nothing about copies being wrong:

Disaster

Do replicas help?

What recovers it

Server or disk dies

Yes: fail over

Redundancy (Health checks & failover)

A zone or region is lost

Yes, if replicas are elsewhere

Multi-region copies (Multi-region replication)

Data deleted or corrupted by a bug or a person

No: the change replicates

A backup from before the change

Ransomware or stolen admin credentials

No: the attacker can reach the replicas, and often the backups

Backups the attacker can't delete

The site holding the backups burns

Only copies kept elsewhere

Off-site backups

None of these rows is hypothetical:

  • 2017: an engineer at a code-hosting company ran a delete on the primary database instead of a replica. About 300 GB was gone in seconds; about 6 hours of data was lost and the site was down for about 18 hours, partly because the regular backups had been silently failing.
  • March 2021: a fire destroyed one data-center building in Strasbourg and badly damaged another. Customers whose paid backups were stored in the same building lost them with it, and a court later ordered the provider to compensate two of them.

2 · The targets

RPO and RTO are business decisions, made per system

Two numbers define what recovery must achieve:

  • Recovery point objective (RPO): the maximum acceptable time between the last recovery point and the disaster, which is the data you agree to lose.
  • Recovery time objective (RTO): the maximum acceptable time between the interruption and restoring service.

They come from the business, through a business impact analysis: what does an hour of downtime, or an hour of lost data, cost? Then they are weighed against the cost of achieving them. A recovery strategy that costs more than the loss it prevents is not worth building, unless a regulator requires it.

The same system can deserve different targets at different times. The payroll service on the 3rd of the month can be down for a day and nobody notices. On the 27th, with payments due on the 28th, an hour matters. Different parts deserve different targets too:

Part of the payroll service

RPO

RTO

Why

Payment instructions and ledger

Minutes

1 hour on payday, 1 day otherwise

Lost payments are real money, owed to real people

Payslip PDFs

24 hours

2 days

Can be regenerated from the ledger

Reporting warehouse

1 week

1 week

Rebuilt from the ledger; nobody is paid from it

Search index

None needed

Hours

Derived data: rebuild it instead of backing it up

One subtlety changes everything about corruption. When data is corrupted, the usable recovery point is before the corruption started, not before it was noticed. A bug that quietly damages records for three days before anyone notices gives a recovery point three days old, whatever the backup schedule says, unless you can repair forward from logs. Keep backups far enough back to reach behind the slowest discovery you can imagine.

3 · Recovery points

Replication is not a backup; point-in-time recovery is

At 14:00 the bad migration ran. The fix is to rebuild the database as it was at 13:59, then re-apply the legitimate changes made since. That needs point-in-time recovery (PITR): a full base backup taken periodically, plus every change since, kept in the database's write-ahead log (Storage engines: B-trees, LSM trees & WAL):

The restored copy is a new database stopped just before the mistake. The team compares it with production and copies back what the migration destroyed, keeping legitimate changes made after 14:00.

How far back you can go, and how much you lose, depends on the method:

Method

Worst-case loss

Protects against

Nightly snapshot only

Up to 24 hours

Deletion and corruption, coarsely

Base backups + continuous log archiving

Minutes (Amazon RDS ships its logs every 5 minutes)

Deletion and corruption, to any moment in the retention window

Synchronous replica

Zero, for hardware loss

Machine and zone failures only; it copies mistakes instantly

Object versioning

Zero for overwritten or deleted files

Mistakes and deletions in object storage (Object & blob storage)

A restore usually creates a new database rather than rewinding the old one. That is a feature: you can inspect the restored copy, and production keeps running while you do. Plan for where it runs, how the app is pointed at it, and how its data reaches production.

4 · Survival

A backup must survive whatever destroyed the original

A backup in the same building, the same account or under the same credentials shares the original's fate. The oldest rule of thumb is 3-2-1: keep 3 copies of important data, on 2 different kinds of storage, with 1 copy off-site. Modern threats add two more requirements:

Payroll databaseregion A, account ProdLocal backupsregion A: fast restoresLocked backup vaultregion B, own accountbase + logscopy acrossPayroll databaseregion A, account ProdLocal backupsregion A: fast restoresLocked backup vaultregion B, own accountbase + logscopy across

Local copies make common restores fast. The vault copy lives in another region, under a separate account the production admins can't reach, and its copies are write-once: undeletable for 35 days.

Why each part matters:

  • Another region survives the loss of a site, unlike the Strasbourg backups.
  • Another account survives stolen production credentials. Ransomware routinely looks for reachable backups to delete or encrypt them before demanding payment.
  • Write-once storage survives even an administrator. S3 Object Lock in compliance mode, for example, prevents anyone, including the account's root user, from deleting a locked version until its retention date.
  • Offline copies are the standard defense against ransomware, together with regular tests that they can actually be restored. Immutable cloud storage is an alternative, configured with care.

Back up more than the database. A restore needs everything that rebuilds the service: infrastructure as code, configuration, machine images, secrets, and the encryption keys for the backups themselves. A backup encrypted with a key that lived only in the lost region can't be read.

5 · Restore time

The RTO you actually have is how long a restore takes

A backup sets the recovery point; the restore sets the recovery time. The payroll ledger is 4 TB. Restore time is roughly size ÷ throughput, before replaying any logs:

  • 100 MB/s
  • 500 MB/s
  • 1 GB/s
01020246810Database size (TB)Hours to copy back (h)

Hours = size ÷ throughput: 4 TB at 100 MB/s is 4,000,000 MB ÷ 100 ÷ 3,600 ≈ 11 hours; at 1 GB/s about 1.1 hours. Throughputs are illustrative; measure your own, end to end.

The copy is only one step. The full recovery time adds:

  • Deciding to restore, and to which moment, which is often the slowest step in a real incident.
  • Provisioning the database and servers, fastest with infrastructure as code.
  • Replaying logs from the base backup to the chosen moment; a week of changes takes far longer than an hour of them.
  • Warming up: some managed restores keep loading data in the background, at reduced performance until done.
  • Repointing the application, DNS and caches at the restored copy.

In the 2017 deletion, the only usable copy sat on cheap network disks in a staging environment, throttled to around 60 megabits per second. Copying it back to production took about 18 hours, most of the outage. Nobody had measured it in advance. If the measured restore time is longer than the RTO, either the strategy changes or the RTO does.

6 · Strategies

Pay for readiness in proportion to the recovery time you need

Shorter recovery times mean more of the recovery is done in advance. The standard ladder of strategies, cheapest first:

Strategy

Ready in the recovery site

What recovery still requires

Cost

Backup and restore

Backups and infrastructure code

Restore all data, deploy everything

Lowest

Pilot light

Data replicated live; servers defined but switched off

Start and scale the servers, switch traffic

Low

Warm standby

A complete, scaled-down copy, serving nothing

Scale up, switch traffic

Medium

Multi-site active/active

Full copies serving users all the time

Shift traffic away from the lost site

Highest

The line between pilot light and warm standby is whether the recovery site can take a request immediately: a warm standby can, at reduced capacity; a pilot light must first start its servers. The standby kinds themselves, and why the idle copy is also untested, are in Redundancy & failure domains; running every region at once is Multi-region replication.

Two warnings apply to every rung:

  • Even active/active needs backups. It recovers from a lost region in seconds, but corruption and deletion replicate to every site, so their recovery point is still the last good backup.
  • Automatic failover to a recovery region is risky. A false alarm costs real data and downtime, so many teams start failover by hand, with every step after the decision automated so that starting it is one command. Recovery should rely on systems that keep running when the primary site fails, not on the failed site's management tools.

7 · In practice

A recovery plan nobody has rehearsed is a hope

The 2017 outage had several backup methods. One had been failing for some time: its version didn't match the database, and its failure emails were being rejected, so nobody knew. Another had never been turned on for the database servers. The lesson in that postmortem is the one in every disaster-recovery guide: backups exist only once they have been restored.

  1. Alert on backup failure, and on backup absence

    A job that silently stops running is the most common way to have no backups.

  2. Restore automatically, on a schedule

    Restore last night's backup into a scratch environment, run checks against it, and record how long it took. That number is your real RTO.

  3. Rehearse the whole plan

    Regularly, have the team recover a system from scratch, including the decision, the runbook, DNS and the people involved.

  4. Write the order of recovery down

    On payday, the ledger comes back first and the reporting warehouse last. Decide that before the disaster, not during it.

A disaster-recovery plan is part of a wider business continuity plan. Restoring the payroll service quickly helps only if the bank connections, the support team and the people who approve payments are available too. Write down who decides, how customers are told, and what happens if the person who knows the runbook is unreachable.

Check yourself

4 questions

1. A bad migration corrupts a table at 14:00. The database has a synchronous standby and a cross-region replica. What is the fastest correct recovery?
2. A bug quietly damages records for three days before anyone notices. Backups run every hour. What is the real recovery point for the damaged records?
3. An attacker steals the production admin credentials. Which backups are most likely to survive?
4. A 4 TB database restores at a measured 100 MB/s. The RTO is 2 hours. What should happen?

Takeaways

Remember this

  • Redundancy survives lost copies; disaster recovery survives wrong copies, such as deletion, corruption and ransomware, which replication spreads everywhere.
  • RPO is the data you may lose and RTO the time you may be down; set both per system from business impact and cost.
  • Point-in-time recovery from base backups and archived logs is what reverses a mistake; replicas cannot.
  • Keep backups 3-2-1, in another region and another account, locked against deletion, with the keys and infrastructure code needed to use them.
  • The real RTO is a measured restore; alert on backup failures and rehearse recovery on a schedule.