System Design (High-Level Design) Module 18 – Delivery, multi-region, disaster recovery and cost
Backups and disaster recovery: RPO and RTO
Set recovery point and recovery time objectives, choose a disaster recovery tier, and prove backups with point-in-time restores and drills.
What you will learn
- Set recovery point and recovery time objectives per system from what loss and downtime cost
- Choose a disaster recovery tier, from backup and restore to multi-site, with its yearly cost
- Restore a database to the moment before a mistake with point-in-time recovery
- Estimate how long a full or partial restore takes before you need one
- Design restore drills that prove backups work
Before you start
What you’ll learn · Before you start
What you will learn
- Set recovery point and recovery time objectives per system from what loss and downtime cost
- Choose a disaster recovery tier, from backup and restore to multi-site, with its yearly cost
- Restore a database to the moment before a mistake with point-in-time recovery
- Estimate how long a full or partial restore takes before you need one
- Design restore drills that prove backups work
Before you start
On this page
At 14:05 a script deletes most of the orders table of a 1.5 TB database, and the replica deletes the same rows a second later. Whether the shop then loses 12 hours of orders or none, and whether it is selling again in two hours or in five, was settled long before, by two numbers that only the business can set. The first is the recovery point objective (RPO): The most data a system may lose in an incident, measured back in time from the incident to the last copy that can be restored. An RPO of one hour allows losing the last hour of writes., how far back from an incident the last copy you can restore may be. The second is the recovery time objective (RTO): The longest a system may take to work again after an incident, from the moment it fails until it serves again., how long the system may take to work again.
Both set the architecture and the bill, because smaller targets need more copies, kept closer to ready. Replication
does not help with mistakes: a replica copies a mistaken DELETE within a second.
RPO and RTO: two numbers that set the design
Google Cloud’s planning guide defines the RTO as the longest time an application may be offline and the RPO as the longest stretch of data that may be lost, and notes that the smaller both are, the more an application costs to run (Google Cloud). Here they are on one line of time:
The recovery point objective and the recovery time objective
Text description of the diagram
Three boxes from top to bottom, in time order, joined by arrows.
- The last copy you can restore.
- The incident: the data is lost or the site is down.
- The service works again.
The arrow from the last copy to the incident is labelled "RPO: how much data you may lose". The arrow from the incident to the service working again is labelled "RTO: how long you may be down".
Set them per system, from what an hour of downtime and an hour of lost writes would cost, then choose the cheapest design that meets them. The program applies three backup setups to the accident above:
# One accident, three backup setups. At 14:05 a script deletes most of the orders table in a 1.5 TB database. How
# much data does each setup lose, and how long does the restore take? Every figure is a labelled assumption: a
# restore reads backups at 300 MB/s, the database writes 5 MB/s of log, replaying log runs at 60 MB/s, and checks
# before reopening take 30 minutes.
DB_GB = 1_500
RESTORE_MB_S = 300
LOG_MB_S = 5
REPLAY_MB_S = 60
CHECKS_MIN = 30
MISTAKE = 14 * 60 + 5 # minutes after midnight
def hours_minutes(minutes):
return f"{int(minutes // 60)} h {int(round(minutes % 60)):02d} min"
def restore_minutes(log_minutes):
"""Copy the backup back, replay `log_minutes` of log on top of it, then check."""
copy = DB_GB * 1_000 / RESTORE_MB_S / 60
replay = log_minutes * 60 * LOG_MB_S / REPLAY_MB_S / 60
return copy + replay + CHECKS_MIN
SETUPS = [
# name, minutes of data lost, minutes of log to replay
("nightly backup at 02:00 only", MISTAKE - 2 * 60, 0),
("hourly snapshots", MISTAKE - 14 * 60, 0),
("nightly base backup + archived log", 0, MISTAKE - 2 * 60),
]
print(f"{'Setup':<38}{'data lost':>14}{'restore takes':>16}")
for name, lost, log in SETUPS:
print(f"{name:<38}{hours_minutes(lost):>14}{hours_minutes(restore_minutes(log)):>16}") Output
Setup data lost restore takes nightly backup at 02:00 only 12 h 05 min 1 h 53 min hourly snapshots 0 h 05 min 1 h 53 min nightly base backup + archived log 0 h 00 min 2 h 54 min
Recorded with Python 3.14.8 on macOS 26 arm64. To run it yourself: mise exec python@3.14.8 -- python3 three_setups.py
Runs on this device, in your browser. The first run downloads Python (about 13.5 MB), which is kept for the next runs.
Your run, in this browser
Nightly backups alone lose 12 hours of orders. Hourly snapshots lose 5 minutes, and a base backup with an archived log loses nothing written before the mistake, at the price of a longer restore, because the log must be replayed. Step through the day of the accident and the three ways back:
The drawing shows the whole scene; its 8 steps are listed below.
Every step as text
- 02:00, the nightly copy. The backups take a full copy of the database. From this moment the base-and-log setup also archives every change the primary commits.
- Every change, at once. The replica applies each committed change within about a second. It protects against a lost machine or zone, not against a mistake.
- 14:00, the last snapshot. The hourly-snapshot setup takes its last copy before the mistake.
- 14:05, the mistake. A script deletes most of the orders table. Nothing is wrong with the database itself; it did what it was told.
- A second later. The replica applies the delete like every other change, so it now holds exactly as little as the primary.
- Way back 1, the nightly copy. Restoring the 02:00 copy loses 12 h 05 min of orders, and copying 1.5 TB back and checking it takes 1 h 53 min.
- Way back 2, the snapshot. The 14:00 snapshot loses only the 5 minutes before the mistake, and the restore takes the same 1 h 53 min.
- Way back 3, base and log. The 02:00 base backup plus the archived log, replayed to just before 14:05, loses nothing written before the mistake. Replaying 12 hours of log makes it the slowest restore, 2 h 54 min.
A slower restore
Press Edit, set RESTORE_MB_S to 100 and run it again: the data lost stays the same, and the restores grow to
4 h 40 min and 5 h 40 min.
Disaster recovery is how a whole system comes back after a disaster: a lost region, a deleted table, a corrupted store. AWS’s paper on it groups the designs into four tiers, from cheap and slow to costly and fast (disaster recovery options):
- Backup and restore: copies of the data, code and configuration are restored into a new environment.
- pilot light: A disaster recovery tier in which data is replicated to a second region whose core stays on, while servers start only during a failover.: data is replicated to a second region with its core always on, and servers start only in a failover.
- warm standby: A disaster recovery tier in which a smaller but working copy of production runs in a second region, ready to take traffic and scale up.: a smaller but working copy of production runs in the second region, ready to scale up.
- Multi-site active/active: every region serves users all the time, so recovery means moving traffic.
Whatever the tier, backups still matter, because replication carries a corruption or a deletion everywhere at once. point-in-time recovery: Restoring a base backup and replaying the archived log of changes on top of it up to a chosen moment, such as one second before a mistaken delete. restores a base backup and replays the log to any moment, and a restore drill proves on a schedule that the whole chain works.
Key idea
Each backup setup trades the data you may lose against the time you are down, and only a copy from before a mistake can undo it.
Checkpoint
Check: RPO and RTO
Choosing a tier by its yearly cost, worked Pro: opens with a Pro, Premium or Ultimate pass
In this part:
- Point-in-time recovery, reproduced
- A base backup and an archived log, restored to one second before a mistake
- How PostgreSQL does it
- Restores are slow: size the job before you need it
- Restore time, with numbers
- Partial restores at scale: an outage of up to 14 days
- Backups that survive the disaster
- Proving backups: restore drills
- Practise: replay a log to a point in time
- Restore a base backup and replay the log to a point in time
- Interview questions
- What are RPO and RTO, and who decides them?
- At 14:05 a developer ran DELETE FROM orders without a WHERE clause on a 1.5 TB PostgreSQL database. Base backups run nightly at 02:00 and the write-ahead log is archived continuously, and the site must keep taking new orders. Walk through the recovery, the data at risk and how long it takes.
- The head of HR asks for zero data loss and zero downtime for the payroll and leave system that 3,000 employees use. Turn that into RPO and RTO targets, choose a disaster recovery tier, and justify its cost.
- Your backups report success every night, but nobody has ever restored one. Design a programme that proves they work: which checks run how often, what each one catches, and who owns the results.
- Key takeaways
4 diagrams · 3 runnable examples (Python) · 1 exercise with sample tests · 3 interview answers · about 45 minutes
Opening this part with your pass…
This part opens with any MySmartCoPilot pass.
- Pro pass · 1 week₹79$2.99
- 30 days₹179$5.99
- 1 year₹1,699$45
One payment; a pass never renews. The price shown is the total you pay: no fees or charges are added at checkout.
Passes can’t be bought right now, so this part can’t be opened at the moment. The free part above stands on its own. If you have a pass, enter your licence key.
It also opens every other in-depth part in Learn and every Pro tool. Sales are final, except where the law gives you a right to withdraw, for example in the EU and the UK (refund policy).
Terms in this lesson
- pilot light
- A disaster recovery tier in which data is replicated to a second region whose core stays on, while servers start only during a failover.
- point-in-time recovery
- Restoring a base backup and replaying the archived log of changes on top of it up to a chosen moment, such as one second before a mistaken delete.
- recovery point objective (RPO)
- The most data a system may lose in an incident, measured back in time from the incident to the last copy that can be restored. An RPO of one hour allows losing the last hour of writes.
- recovery time objective (RTO)
- The longest a system may take to work again after an incident, from the moment it fails until it serves again.
- warm standby
- A disaster recovery tier in which a smaller but working copy of production runs in a second region, ready to take traffic and scale up.
References
- Disaster Recovery of Workloads on AWS: disaster recovery options in the cloud (Amazon Web Services)
- Disaster recovery planning guide (Google Cloud)
- PostgreSQL 18 documentation: Continuous Archiving and Point-in-Time Recovery (The PostgreSQL Global Development Group)
- PostgreSQL 18 documentation: Replication settings (recovery_min_apply_delay) (The PostgreSQL Global Development Group)
- Amazon S3: understanding and managing storage classes (Amazon Web Services)
- Atlassian: post-incident review of an outage that deleted customer sites (Atlassian)
- GitLab: postmortem of a database outage (GitLab)
Related tools
Report a problem with this lesson
Kept only in this browser. Your Learn progress