Skip to content

Disaster recovery: RPO and RTO

Most failures in this module are small: an instance, a link, a slow database. A disaster is the loss of something large, such as a data centre, a region, or the data itself through corruption or a mistaken deletion. Surviving one needs a second place to run and a copy of the data, and two decisions that the business has to make before it happens.

Google’s disaster recovery guide defines them. The recovery time objective (RTO) is the maximum acceptable length of time that the application can be offline. The recovery point objective (RPO) is the maximum acceptable length of time during which data might be lost because of a major incident. One is about the service and the other is about the data, and they are set separately. Smaller values for either cost more, and Google ties the choice between a cold, warm or hot pattern to them.

Mental model. RTO is how long you wait for the service. RPO is how far back the data is when it returns. A recovery is a point on a curve between what you pay and what you lose.

The failure lab for a primary database is a disaster in miniature. The shop writes to a primary, and its replica is far away: 250 ms there and back. Press Kill the primary (failover). Writes fail until a replica is promoted, which the lab does 30 seconds after the failure.

Kill the primary (failover)

The shop sends its writes to one primary database and its reads to two replicas. Replication is asynchronous: the primary tells the client a write succeeded as soon as it has it, and sends it on to the replica, which is far away, 250 ms there and back. You kill the primary. Writes fail until a replica is promoted, which takes 30 seconds from the failure here. Watch the writes that fail, then count the writes the primary had acknowledged that the replica never received. Then decide what you would have built differently and run the same failure again.

The failure lab needs JavaScript. The healthy system is shown below.

1. Break it

The healthy system is shown first. When you press the button the failure strikes, and the run follows the 60 seconds after it.

What the failure does: The primary database stops answering. Writes have nowhere to go until a replica is promoted. Reads carry on.

Replica servers0.3 ms0.5 ms0.5 ms250 msClientsHealthy<1%APIBusy75%PrimaryHealthy9%ReplicasHealthy36%ReplicationHealthy45%
Replica servers0.3 ms0.5 ms0.5 ms250 msClientsHealthy<1%APIBusy75%PrimaryHealthy9%ReplicasHealthy36%ReplicationHealthy45%

Each dot stands for many requests. The numbers show the real rate.

A dashed arrow is a call the sender does not wait for: the primary sends each write on and carries on.

No bottleneck: every component has headroom.

0 ms
What happens to the data

Figures from the model at the moment shown. They change as the run plays.

Then, with no one pressing a button: A replica is promoted to primary after 30 s.

Writes have been failing for
—
The seconds in which more than half of the writes were refused.
Writes refused so far
—
Writes the primary could not take. The client was told that each one failed.
Acknowledged writes the replica never received
—
Writes the primary had told clients succeeded that had not reached the replica when it died: the writes still on their way. A primary that waits for the replica has not acknowledged them yet.
Time a write takes at the database
—
From the API to the primary, and to the replica too when the primary waits for it.

Cause and effect

Each step leads to the next. A step that is changing right now is marked.

Metrics
ComponentStateUtilisationOffered (req/s)Served (req/s)Rejected (req/s)p50p95p99
ClientsHealthy<1%90090000 ms0 ms0 ms
APIBusy75%900900014 ms60 ms93 ms
PrimaryHealthy9%18018002.8 ms12 ms18 ms
ReplicasHealthy36%72072005.5 ms24 ms37 ms
ReplicationHealthy45%18018003.2 ms14 ms21 ms
Traffic
900 req/s
Successful
900 req/s
Error rate
0%
Mean latency
28 ms

Illustrative values, not benchmarks of any real product.

Model notes

Assumptions

  • Requests arrive at random, as a Poisson process, at a constant average rate.
  • Each node is one queue, served first-come first-served by several identical slots (instances × concurrency).
  • Service times are random with the stated mean; by default they are exponentially distributed.
  • Each node is analysed separately, with the traffic it receives treated as Poisson.
  • The system starts healthy at 900 requests a second. One request in five writes, 180 writes a second, and four in five read, 720 reads a second. Three API instances can serve 1,200 requests a second, the primary 2,000 writes a second, and the two replicas together 2,000 reads a second.
  • Replication is asynchronous: the primary acknowledges a write as soon as it has it, and sends it to the replicas without waiting for them. Each replica applies the stream at up to 400 writes a second. The diagram shows one replica's apply stage, since the replicas are alike and fall behind together.
  • The link to the replicas takes 250 ms there and back, so a write reaches a replica 125 ms after the primary acknowledged it, and is applied a few milliseconds after that, longer if the replica has a backlog.
  • A failure strikes at one instant. Nothing repairs it except the steps the lab lists, which happen at fixed times: no restart, no operator, no autoscaling.
  • A replica is promoted 30 seconds after the failure. The figure is illustrative: it stands for noticing that the primary is gone, then promoting a replica. A fix can shorten it.

Simplifications

  • Nothing detects the failure and no one decides: the promotion comes at a fixed time. How long a real failover takes depends on how the failure is detected and who promotes.
  • The promoted replica takes over at once with everything it received, and the old primary never returns. A real failover must also stop the old primary from accepting writes if it comes back, which the PostgreSQL documentation calls STONITH. This lab does not simulate that, or the two-primaries situation it prevents.
  • Every acknowledged write that the promoted replica did not have counts as lost. Some may still be on the failed primary’s disk, if it can be read.
  • Promoting a replica takes it out of the replicas, so the reads that remain run on one. Nothing replaces it during the run.
  • Sending a write to a replica and applying it are one stage with one rate here. Real databases report them separately (PostgreSQL has write, flush and replay lag): what a primary loses when it dies is what never reached a replica, while what a read returns depends on what has been applied.
  • A replica applies the stream and answers reads in two separate components, so reads stay fast while it lags. A real replica does both with the same machine.
  • Nothing is retried: a write that fails is refused to the client, and the client does not send it again.
  • Every replica is the same and falls behind by the same amount. A real replica can be slower than its siblings.
  • Above capacity there is no steady state. The model switches to a fluid approximation: the node serves at capacity, its queue grows until it reaches its limit, and further requests are rejected.
  • Percentiles assume an exponential tail. A service-time variability other than exponential changes the mean wait but not the shape of the tail.
  • A node frees its slot as soon as it has done its own work, before waiting on the services it calls. Real thread-per-request servers hold the slot, so a slow dependency exhausts them faster than this model shows.
  • A request calls its dependencies one after another. Parallel fan-out is not modelled.
  • When a caller times out and gives up, the callee still finishes the work, so abandoned requests keep consuming capacity.
  • Retries add load. Their backoff and jitter decide when that load arrives, which only the per-request simulation shows.
  • A caller’s timeout counts the mean time its dependencies take, not their full distribution.
  • Latency percentiles for a whole request are estimated, over every request, including those that are rejected and fail quickly. The mean is exact, and the percentiles come from a gamma distribution that has that mean and the variance of the time spent in each component.

Parameter values are illustrative. They are not benchmarks of any real product.

Read the two measures the lab reports. The time writes failed is 30 s: that is the recovery time for writes. The acknowledged writes lost is about 23: that is the recovery point. The replica receives each write 125 ms after the primary has it, and at 180 writes a second 180 × 0.125 is about 23 writes on their way when the primary dies. Clients were told those writes had succeeded, and the replica that takes over does not have them. In time, the recovery point is 125 ms of writes. Reads were not affected.

Now move each number, one change at a time, and run the same failure again.

Change Time writes failed Writes lost A write takes
None 30 s 23 4.5 ms
Detect the failure and promote sooner (10 s) 10 s 23 4.5 ms
Keep a replica close to the primary 30 s 1 4.5 ms
Wait for the replica before acknowledging a write 30 s 0 259 ms

Faster detection moves the RTO from 30 s to 10 s, and 1,800 writes are refused instead of 5,400. It does nothing for the RPO. The price is a primary that is only slow or briefly unreachable being declared dead. The replica nearby moves the RPO: about 1 write on its way instead of 23, because the copy takes 1 ms and not 125 ms. Its price is the disaster itself: a replica next to the primary shares its fate when the whole site is lost, and the lab counts writes only, so it does not show that. Waiting for the replica gets the RPO to zero, because a write the replica does not have is not acknowledged, and costs every write a round trip, 259 ms instead of 4.5 ms. That is the same trade-off the replication module showed, now with names.

The failover above recovers from a replica that is a copy a moment behind. A backup is a copy that is further behind, by design. If you back up once a day, the data you can lose is everything written since the last backup, up to 24 hours. At 180 writes a second, that is 180 × 86,400, which is 15,552,000 writes. Backing up every hour cuts it to 180 × 3,600, which is 648,000. The backup interval is the RPO.

A replica is not a backup. AWS notes that continuous replication protects against some disasters but not against data corruption or malicious deletion unless the strategy includes versioning or point-in-time recovery, because a mistake is copied to the replica. A backup that you can restore to a point before the mistake covers what replication does not. AWS also advises backing up the configuration and the infrastructure definition, not only the data, because the RTO includes redeploying the system.

AWS describes four strategies, from cheap and slow to expensive and fast. They differ in what runs in the recovery site before the disaster.

Strategy What exists in the recovery site Recovery
Backup and restore Backups of the data, and the code to redeploy Redeploy and restore everything, then switch
Pilot light The data replicated and the core infrastructure; application servers switched off Switch on and scale out
Warm standby A scaled-down but fully working copy that is always on Scale up; it can already take traffic at reduced capacity
Active-active The workload runs in several regions at once There is no failover: traffic leaves the failed region

AWS calls active-active the most complex and costly strategy, with recovery time near zero for most disasters, and notes that a data disaster still needs backups, which gives a recovery point earlier than the incident. For the same reason, it advises caution with failovers that start on their own from a health check: a false alarm costs the downtime and the data loss that a real disaster would, so many organisations start the failover by hand and automate every step of it.

What happens if you never test the restore?

Section titled “What happens if you never test the restore?”

A plan on paper has an RTO and an RPO that are guesses. The restore may fail because the backup is corrupt, the infrastructure definition is out of date, a quota in the recovery site is too low, or the person who knows the steps is away. AWS’s guidance is blunt: regularly assess and test the strategy, so that you have confidence in invoking it, and test your backups by restoring them. The numbers worth writing down are measured ones: the time the last restore took, and the age of the data it restored. The next lesson turns that into a habit.

Check your understanding: RPO and RTO

This quiz needs JavaScript to check your answers.

Question 1 of 3

A shop backs up its database once a day, at 02:00. A disaster destroys the database at 18:00 and the backup of 02:00 is restored.

What does the daily schedule decide, and what is lost here?

Choose one answer.

Question 2 of 3

A service takes 180 writes a second. Its database is backed up every hour, and a disaster strikes just before the next backup.

How many writes can be lost, at worst?

Enter a number and choose its unit.

writes
Question 3 of 3

To lower the data lost in a failover, a team puts the replica in the same rack as the primary, 2 ms away instead of 250 ms.

What does this not protect against?

Choose one answer.

  • RTO is the longest acceptable downtime and RPO the most data, measured in time, that may be lost. Smaller values cost more.
  • In the lab the primary dies and writes fail for 30 s, which is the recovery time for writes. About 23 acknowledged writes are lost, 180 × 0.125, which is 125 ms of writes: the recovery point.
  • Promoting after 10 s moves the RTO and not the RPO. A replica nearby (1 write lost) or waiting for the replica (0 lost, 259 ms per write instead of 4.5 ms) move the RPO and cost resilience or latency.
  • A backup interval sets the RPO: daily at 180 writes a second can lose 15,552,000 writes, hourly 648,000. A replica copies a mistake, so it is not a backup.
  • The four strategies run more in the recovery site as the RTO and RPO fall: backup and restore, pilot light, warm standby, active-active.
  • Untested plans have guessed numbers. Restore the backup, run the failover, and write down what you measured.

Next: failure injection and chaos experiments.

Your progress

Built by GhaziAlibi.

© ShardCraft. All rights reserved.