Pidoku

Archive

This learning material is in the archive. It is not currently maintained and has not been updated with the latest information, so tool versions, prices and dates may be out of date.

Disaster Recovery

Module 9 Lesson 9.b 50 min Difficulty 4/5

Prerequisites 9.a, 7.a

The idea in one minute#

Disaster recovery (DR) is the plan for losing something big: a region, a data centre, an account, a critical vendor, or your data’s integrity. There are four standard strategies, in increasing cost and decreasing recovery time: backup and restore, pilot light, warm standby, and multi-site active-active. Pick per service, from its RPO and RTO and what an hour of downtime costs.

A DR plan is worth exactly what its last test proved. Plans that have not been exercised fail on details — expired credentials, missing quotas in the other region, a DNS TTL of a day, a runbook that assumes the primary region’s tooling is up.

An analogy#

A household’s plans for a house fire, in increasing cost: insurance and a box of documents at a relative’s house (backup and restore); a rented storage unit with the essentials (pilot light); a fully furnished second flat (warm standby); living in two houses at once (active-active).

A picture#

flowchart LR
  subgraph S1["Backup & restore"]
    B1["Region B: nothing running<br/><small>backups only</small>"]
  end
  subgraph S2["Pilot light"]
    B2["Region B: data replicated,<br/>core infra off or minimal"]
  end
  subgraph S3["Warm standby"]
    B3["Region B: full stack running<br/>at reduced size"]
  end
  subgraph S4["Active-active"]
    B4["Region B: serving traffic<br/>at full size"]
  end
  S1 -->|"cheaper, slower"| S2 --> S3 -->|"costlier, faster"| S4
  class B1 neutral
  class B2 memory
  class B3 queue
  class B4 io

How it really works#

The four strategies#

StrategyRecovery region hasRPORTORelative cost
Backup and restoreBackups (and IaC to build everything)Hours (backup interval)Hours to a dayLowest
Pilot lightData continuously replicated; app tier off or minimalSeconds–minutesTens of minutes to hoursLow
Warm standbyA scaled-down but working copy of the full stackSeconds–minutesMinutesMedium
Multi-site active-activeFull capacity, serving users~0 (with care)Near zeroHighest (and the most complex data design)

(These are the names AWS uses in its DR whitepaper; the ideas apply on any provider or on-premises.)

Active-active across regions is not just “more servers”: it needs a data design that tolerates two sites writing — per-region data ownership (cells, 7.c), conflict resolution, or a globally consistent database (Spanner, CockroachDB, Aurora DSQL-style designs) with its latency cost.

What a DR plan contains#

  1. Scope: which services, which disasters (region loss, account compromise, data corruption, vendor loss).
  2. Objectives: RPO and RTO per service, agreed with owners.
  3. Decision: who declares a disaster and triggers failover — a named role, with criteria. Failing over is itself risky; do not do it for a 10-minute blip.
  4. Order of recovery: dependencies first (identity, DNS, secrets, databases), then services in priority order.
  5. Runbooks for each step, runnable without the primary region — tooling, CI, secrets, and the runbooks themselves must be reachable from the recovery side.
  6. Capacity: quotas and instance capacity in the recovery region (a whole region failing over to yours at the same moment as everyone else’s).
  7. Failback: how to return, including re-syncing data written during the disaster.
  8. Communication plan (5.b).
  9. Test schedule and the results of the last test.

Static stability#

Design the recovery path so it does not need the failed region’s control plane. If failing over requires calling an API in the region that is down — to change DNS, scale a group, or read a secret — the plan fails. Pre-provision, pre-authorise, and prefer data-plane mechanisms (health- checked DNS failover, anycast, already-running standby capacity) over control-plane actions at the moment of disaster.

Testing DR#

TestWhat it proves
Tabletop walk-throughThe plan is complete and people know their roles
Component failover (one database, one service)That component’s runbook works
Full failover of a non-production environmentThe whole sequence works and how long it takes
Production failover (planned, during low traffic)The real thing works — the only proof

Google’s annual DiRT (Disaster Recovery Testing) exercises — taking down whole data centres, or making key people unavailable — are the best-known example (10.c).

A worked example#

A company has three services:

ServiceRPORTOCost of an hour down
Storefront + checkout1 min15 min$200,000
Internal reporting24 h2 days$2,000
Customer support tool15 min4 h$10,000

Choices:

  • Checkout: warm standby in a second region — database replica, app tier at 30% size with autoscaling allowed to 100%, health-checked DNS failover with a 60-second TTL. Annual test.
  • Reporting: backup and restore — nightly warehouse snapshots copied cross-region; IaC to rebuild.
  • Support tool (a SaaS vendor): a review of the vendor’s own DR commitments in the contract, plus a pilot light of its own: ticket data streamed every few minutes from the vendor’s export API into the company’s storage, and a minimal read-only viewer that can be scaled up if the vendor is lost.

The first full production failover test of checkout takes 41 minutes instead of 15, because the standby region’s quota allowed only 40% of the needed instances and the increase needed a support ticket. Fixed in advance, the second test takes 12.

The program picks the cheapest strategy that meets each service’s RPO and RTO, and compares the yearly cost of the strategy with the expected cost of downtime.

Code#

Go
// dr.go — choose the cheapest DR strategy that meets RPO and RTO, and compare with expected loss.
package main

import (
	"fmt"
	"time"
)

type strategy struct {
	name     string
	rpo, rto time.Duration
	costPerY float64 // yearly cost for a service of "unit" size
}

type service struct {
	name       string
	rpo, rto   time.Duration
	sizeFactor float64 // multiplier on strategy cost
	lossPerH   float64 // cost of an hour of downtime
}

func main() {
	strategies := []strategy{
		{"backup & restore", 24 * time.Hour, 24 * time.Hour, 5_000},
		{"pilot light", 5 * time.Minute, 2 * time.Hour, 20_000},
		{"warm standby", time.Minute, 15 * time.Minute, 60_000},
		{"active-active", 0, time.Minute, 180_000},
	}
	services := []service{
		{"storefront + checkout", time.Minute, 15 * time.Minute, 3, 200_000},
		{"internal reporting", 24 * time.Hour, 48 * time.Hour, 1, 2_000},
		{"support data export", 15 * time.Minute, 4 * time.Hour, 0.5, 10_000},
	}
	const regionLossPerYear = 0.1 // chance a year of a region-scale disaster lasting a day

	for _, s := range services {
		fmt.Printf("%s (RPO %v, RTO %v)\n", s.name, s.rpo, s.rto)
		chosen := ""
		for _, st := range strategies {
			meets := st.rpo <= s.rpo && st.rto <= s.rto
			cost := st.costPerY * s.sizeFactor
			// Expected yearly downtime loss if a region disaster happens: RTO hours × loss/h × probability.
			expLoss := regionLossPerYear * st.rto.Hours() * s.lossPerH
			mark := "  "
			if meets && chosen == "" {
				chosen = st.name
				mark = "→ "
			}
			fmt.Printf("  %s%-18s meets=%-5v cost $%8.0f/y   expected outage loss $%9.0f/y\n",
				mark, st.name, meets, cost, expLoss)
		}
		if chosen == "" {
			fmt.Println("  no strategy meets the objectives — revisit them with the owner")
		}
		fmt.Println()
	}
}

Read each block from the arrow down: the arrow marks the cheapest strategy that meets the objectives. For checkout, the expected-loss column also shows why the objectives were right — backup and restore would be cheap to run and ruinous in a disaster.

Remember this#

  • Four strategies: backup & restore, pilot light, warm standby, active-active — cost against RPO/RTO.
  • Choose per service, from its objectives and the cost of downtime.
  • The plan names who declares a disaster, the recovery order, runbooks that work without the primary region, capacity and quotas, and failback.
  • Design for static stability: the recovery path must not depend on the failed control plane.
  • The plan is worth what its last test proved — test in production when you can.

Try it#

  1. Run dr.go. Change checkout’s RTO to 1 hour. Which strategy is chosen now, and is the expected loss acceptable?
  2. Write the “order of recovery” list for a system you know. What must come back first?
  3. Check whether your recovery region has the quota for a full failover today.

Check yourself#

  1. What is the difference between pilot light and warm standby?
  2. Why does active-active need a data design, not just more servers?
  3. What is static stability, and why does it matter during a region failure?
  4. Name three things that commonly break during a first DR test.

Sources#

↑↓ navigate↵ openesc close

100% drag to pan · scroll or pinch to zoom · double-click to zoom in