Your country

Tools that support it use your country for local currency, number formats, units and paper size. Your choice is saved only in this browser.

Type a name or a two-letter code. Use the up and down arrow keys to move through the countries, Enter to choose one and Escape to close.

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.

  • Intermediate
  • 25 minutes
  • Examples run with Python 3.14.8, Pyodide 314.0.7, Node.js 24.21.0 and quickjs 0.32.0
  • By MySmartCoPilot
Free intro, Pro: 6 of 25 minutes free
Free: RPO and RTO: two numbers that set the design. With a pass: the other 8 sections and 3 interview answers, about 19 minutes.

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:

A timeline: the last restorable copy, then the incident, then the service working again, with the RPO and RTO between.Last copy you can restoreIncident:the data is lost or the site is downThe service works againRPO: how much datayou may loseRTO: how longyou may be down

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.

  1. The last copy you can restore.
  2. The incident: the data is lost or the site is down.
  3. 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 Python · three_setups.py
# 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

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:

Interactive · message by message One accident and three ways back Step through the day of the accident, then each backup setup's way back. The numbers are the program's.
One accident and three ways back, step 8 of 8. Messages so far: Primary to Backups: nightly copy; Primary to Replica: every change; Primary to Backups: snapshot at 14:00; Primary to Replica: DELETE; Backups to Primary: copy of 02:00; Backups to Primary: snapshot of 14:00; Backups to Primary: base + log to 14:04:59.Primary1.5 TB of ordersReplicaanother zoneBackupsstored apartnightly copyevery changesnapshot at 14:00DELETEcopy of 02:00snapshot of 14:00base + log to 14:04:59

The drawing shows the whole scene; its 8 steps are listed below.

Every step as text
  1. 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.
  2. 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.
  3. 14:00, the last snapshot. The hourly-snapshot setup takes its last copy before the mistake.
  4. 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.
  5. A second later. The replica applies the delete like every other change, so it now holds exactly as little as the primary.
  6. 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.
  7. 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.
  8. 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

  1. Question 1 of 2 A database is copied by hourly snapshots, the last one at 14:00. A script deletes most of a table at 14:05. If the 14:00 snapshot is restored, which writes are lost?

    Choose one answer.

    Show the answer: Question 1 of 2

    Answer: The writes between 14:00 and 14:05, the five minutes before the mistake

    The recovery point is measured back from the incident to the last copy you can restore. With the 14:00 snapshot that is 5 minutes, the program's second row; the restore itself still takes 1 h 53 min, which is the RTO side.

  2. Question 2 of 2 The orders were deleted on the primary at 14:05. Why can the replica in another zone not bring them back?

    Choose one answer.

    Show the answer: Question 2 of 2

    Answer: It applied the same delete about a second later, like every other change

    Replication protects against losing a machine or a zone. Against a mistake or corruption it does nothing, because the mistake is replicated too; only a copy from before the change can bring the data back.

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.

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).

Read a complete sample first: Design a unique ID generator

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

Related tools

Report a problem with this lesson

Quick answers and tool search

Type to search tools or to get a quick answer, for example 18% of 2500. Use the up and down arrow keys to move through the results, Enter to choose, and Escape to close.