Sub topic 11
Setting recovery time and recovery point objectives
This chapter assumes you know what availability percentages mean, how active-active and active-passive designs differ, and how synchronous and asynchronous replication work. It covers how to turn a business need into two numbers, the recovery time objective and the recovery point objective, and how to check that a design can meet them.
Two questions after every failure
When a component fails, the business asks two things.
- How long can the service stay down?
- How much recent data can we afford to lose?
The first answer is the recovery time objective (RTO). It is the longest acceptable time between the start of an outage and the point where the service works again. The second answer is the recovery point objective (RPO). It is the longest acceptable span of data, measured in time, that may be lost. An RPO of 5 minutes means that after recovery, the system may be missing at most the last 5 minutes of writes.
Both are objectives, which means they are targets you choose and design for. They are not measurements. What you actually achieve in a real incident is the actual recovery time and the actual data loss. A design is sound only when the achieved values, observed in tests, stay under the objectives.
| Term | Measures | Unit | Driven mainly by |
|---|---|---|---|
| RTO | Time until service is restored | Seconds to hours | Failover mechanics, detection, automation |
| RPO | Window of data that may be lost | Seconds to hours | Replication method, backup frequency |
RTO and RPO are independent. A system can fail over in 20 seconds (low RTO) and still lose the last 10 seconds of writes (nonzero RPO). Another can lose no data (RPO zero) but need an hour of manual work to come back.
What contributes to RTO
RTO is the sum of the stages in the failover sequence. If you have followed the detect, decide, switch, verify model, you can budget each stage.
- Detection time. With a health check interval of 5 seconds and a rule that needs 3 consecutive failures, detection takes about 15 seconds after the failure.
- Decision time. Automated systems decide in milliseconds. A human who must be paged, wake up, log in, and confirm may take 10 to 30 minutes.
- Switch time. Promoting a replica, moving a virtual IP, updating a load balancer, or changing DNS. DNS changes also wait for cached records to expire, so a 300-second TTL can add up to 5 minutes for some clients.
- Warm-up and verification time. A promoted standby may have cold caches, may need to replay logs, or may need to start application processes before it can take full traffic.
You can estimate an RTO budget by adding the worst case of each stage.
def rto_budget(check_interval, failures_needed, decision, switch, dns_ttl, warmup):
detection = check_interval * failures_needed
total = detection + decision + switch + dns_ttl + warmup
return {
"detection": detection,
"decision": decision,
"switch": switch,
"dns_ttl": dns_ttl,
"warmup": warmup,
"total": total,
}
automated = rto_budget(5, 3, 1, 10, 60, 30)
manual = rto_budget(5, 3, 900, 120, 300, 60)
print("automated:", automated["total"], "seconds") # 116 seconds
print("manual:", manual["total"], "seconds") # 1395 secondsThe automated design totals 116 seconds. The manual design totals 1395 seconds, about 23 minutes, and the human decision step is most of it. If the business needs an RTO of 5 minutes, automation is a requirement, not an optimization.
What contributes to RPO
RPO depends on how state reaches a second location before the failure.
- Synchronous replication. A write is acknowledged only after the replica has it. Data loss on failover is zero, so RPO is 0. The price is added write latency, and the primary may stall or refuse writes if the replica is unreachable.
- Asynchronous replication. The primary acknowledges first and ships changes later. RPO equals the replication lag at the moment of failure, which can grow under heavy write load or a slow link.
- Periodic backups or snapshots. RPO is up to the full interval between backups. Nightly backups give an RPO of up to 24 hours.
The common mistake is to quote the average lag as the RPO. An RPO is a worst-case promise, so you should compare it with the peak or a high percentile of lag, such as the 99th percentile over a busy week.
def worst_case_rpo(lag_samples_seconds, percentile=0.99):
ordered = sorted(lag_samples_seconds)
index = min(len(ordered) - 1, int(len(ordered) * percentile))
return ordered[index]
samples = [0.2, 0.3, 0.2, 0.4, 0.3, 0.5, 0.2, 0.3, 12.0, 0.4]
average = sum(samples) / len(samples)
print(round(average, 2)) # 1.48
print(worst_case_rpo(samples)) # 12.0The average lag looks fine at about 1.5 seconds. The worst sample is 12 seconds, and that is the value a failure at the wrong moment would cost you. If the RPO target is 5 seconds, this system misses it even though its average looks safe.
Choosing objectives from business impact
Start from the cost of downtime and data loss, not from what the technology can do. For each service, ask the business owners two things: what is lost per minute of downtime, and what is the consequence of losing recent data.
- A payment ledger can rarely lose a committed transaction. It needs an RPO of 0 and a short RTO.
- A product search index can be rebuilt from the source database. It tolerates an RPO of hours, because the data is derived, and a moderate RTO.
- An internal reporting dashboard may accept an RTO of a day and an RPO of one day.
Tiering keeps this manageable. Group services into a small number of tiers and assign each tier standard objectives and a standard pattern.
| Tier | Example service | RTO | RPO | Typical design |
|---|---|---|---|---|
| 1 | Payments, login | Under 1 minute | 0 | Active-active, synchronous replication in a quorum |
| 2 | Order history, messaging | Under 15 minutes | Under 1 minute | Active-passive with automated failover, asynchronous replication |
| 3 | Reporting, internal tools | Hours | Hours | Restore from backups in a standby location |
The numbers in the table are examples. Your own tiers should come from your own cost analysis.
Cost grows steeply as objectives shrink
Each step toward zero costs more. Going from an RTO of 4 hours to 15 minutes means a standby that is already running and automation to promote it. Going from 15 minutes to 30 seconds means active-active capacity, fast detection, and clients that retry across endpoints. Going from an RPO of 1 minute to 0 means synchronous replication, with its latency cost and its dependence on the replica being reachable.
For this reason, push back on a request for "zero downtime and zero data loss" for every service. Present the cost of each tier and let the business choose.
Tension between detection speed and RTO
You can shorten detection by checking more often and tripping after fewer failures. This also raises the rate of false positives, where a healthy node is declared dead because of a brief network delay. An unneeded failover can itself cause an outage, and with asynchronous replication it can lose data for no reason. Tune detection against the RTO budget, so that you spend only the seconds you need.
Check the design against the objectives
An objective means nothing until you have evidence that the system meets it. Use this checklist for each tier.
- Write the failover steps and assign a worst-case duration to each.
- Add the durations and compare the total with the RTO.
- Measure peak replication lag, or the backup interval, and compare it with the RPO.
- Run a failover test and record the actual recovery time and the actual data loss.
- Repeat the test after major changes, since data volume growth and new dependencies slow recovery over time.
Common errors
- Treating RTO and RPO as one number. They constrain different parts of the design and must be set separately.
- Quoting the target as if it were achieved. An objective is met only when a test shows it.
- Ignoring dependencies. If your service has an RTO of 1 minute but depends on a database with an RTO of 30 minutes, the service's real RTO is 30 minutes.
- Forgetting client behavior. Clients with long timeouts or cached DNS answers extend the time users see an outage, even when the server side has recovered.
- Counting only the failover, not the recovery of redundancy. After failover you run without a spare until the failed node is rebuilt, which affects how exposed you are to a second failure.
Exercise
A service has these figures: health checks every 10 seconds and 3 consecutive failures to trip, an automated decision of 1 second, a switch of 15 seconds, a DNS TTL of 60 seconds, and 20 seconds of warm-up. Its replica uses asynchronous replication, with a 99th percentile lag of 8 seconds. The business requires an RTO of 2 minutes and an RPO of 5 seconds. Does the design meet each objective, and what is the simplest change for any objective it misses?
Show answer
Detection is 10 x 3 = 30 seconds. The RTO total is 30 + 1 + 15 + 60 + 20 = 126 seconds, which is over the 120-second target. The RPO is the worst-case lag of 8 seconds, which is over the 5-second target. Both objectives are missed. To fix RTO, lower the DNS TTL to 30 seconds, or use a check interval of 5 seconds, which makes the total about 96 seconds or 111 seconds. To fix RPO, move to synchronous replication, or semi-synchronous replication, or reduce the lag by improving the replication link or write load. Synchronous replication brings RPO to 0 at the cost of write latency.
Exercise
A team says their RPO is 1 second because the average replication lag over a month is 0.4 seconds. Why is that claim unsafe, and what should they measure instead?
Show answer
An RPO is a worst-case promise, and an average hides spikes. A failure during a lag spike, for example during a batch job or a network slowdown, loses everything written during the spike. They should measure the peak and the 99th or 99.9th percentile of lag over a representative period, including busy times, and compare that value with the objective. They should also alert when lag approaches the RPO.