KAHIBARO
Discord Login Register

28.3. Disaster Recovery

Why Disaster Recovery Matters

Things will go wrong in production. Disks fail, bugs ship, regions go offline, someone runs DROP TABLE on the wrong database. Disaster recovery is about planning how your backend survives serious failures and how you bring it back online with minimal data loss and downtime.

If you do not plan this in advance, you will be forced to improvise under pressure, which usually leads to more data loss and longer outages.

Disaster recovery is mostly about strategy and process, not fancy tools. You will reuse concepts you already know, such as backups, replicas, and monitoring, and combine them into a coherent plan.

Key Concepts: RPO and RTO

Two metrics appear in every disaster recovery discussion:

Example:

DR Core Metrics

  • Recovery Point Objective (RPO): Maximum acceptable age of recovered data.
    Example: RPO = 10 minutes.
  • Recovery Time Objective (RTO): Maximum acceptable time to restore service.
    Example: RTO = 30 minutes.

Think in terms of trade-offs:

RequirementRough RPORough RTOTypical cost / complexity
Personal blog24 hours24 hoursLow, daily backups
Small SaaS with paying customers5–15 minutes15–60 minutesModerate, frequent backups + replicas
Payment processing system< 1 minuteA few minutesHigh, multi-region, hot standby

Your job is not to get RPO and RTO to zero. Your job is to match them to business needs at a reasonable cost and then design your system to meet them.

Types of Disasters

Disasters are not only region-wide outages. It is helpful to classify them, because mitigation strategies differ.

Logical vs Physical Disasters

Logical disasters are caused by data corruption or mistakes at the software or human level.

Examples:

Physical disasters affect infrastructure.

Examples:

Logical disasters often require point-in-time recovery. Physical disasters often require redundant infrastructure.

Scope of Impact

You can also categorize by scope:

ScopeExampleTypical mitigation
Single componentOne DB instance failsReplication, automatic failover
Single servicePayments service is brokenGraceful degradation, circuit breakers
Single regionCloud region loses networkMulti-region deployment, DNS failover
GlobalCloud provider major outage, widespread DNS issueMulti-cloud or accept downtime

Do not over-engineer for global disasters if your system cannot yet tolerate a single database crash. Start with the most likely and most impactful failures.

Disaster Recovery Strategies

Disaster recovery strategies describe where your data and services exist and how you switch to a healthy copy.

Backup-Based Recovery

This is the simplest and most common strategy for many small and medium systems.

Process:

  1. Take regular backups of the primary database and critical storage.
  2. Store backups in a different location (for example, another region or bucket).
  3. When a disaster happens, restore from the latest good backup to a new instance.
  4. Point your application at the restored instance.

Pros:

Cons:

Use this when:

Cold, Warm, and Hot Standby

For lower RPO and RTO, you use a standby system, which is a second environment that can take over.

Cold Standby

Characteristics:

Example: A secondary region where you only store periodic database backups and Terraform configs, but no running instances.

Warm Standby

In a disaster:

Characteristics:

Hot Standby (Active-Passive or Active-Active)

Hot standby (active-passive):

Active-active:

Characteristics:

Standby Environments

  • Cold standby: Cheap, slow to recover.
  • Warm standby: Medium cost, medium recovery time.
  • Hot standby: Expensive, fast recovery, often near-zero RPO/RTO.

Multi-AZ and Multi-Region

Cloud providers often give you availability zones (AZs) inside a region and multiple regions across geographic areas.

Typical pattern:

Multi-region often implies:

Designing a Disaster Recovery Plan

A disaster recovery plan is a documented, testable set of procedures that explain exactly what to do when a disaster happens.

Identify Critical Components and Data

List your system components and decide which are critical to minimal service.

Examples:

ComponentIs critical?Reason
Primary PostgreSQL DBYesContains all user and business data
Redis cacheNoCan be rebuilt from database
Authentication serviceYesWithout it, no one can log in
Email sending serviceMaybeMight be delay-tolerant in some systems
Metrics dashboardNoHelpful but not required to serve traffic

Also identify critical data stores:

You only need full DR for critical components. Others can use simpler mitigation, such as recreating from code or resynchronizing later.

Define RPO and RTO per Component

For each critical component, define:

Example table:

ComponentRPO targetRTO targetNotes
PostgreSQL DB5 minutes30 minutesFrequent backups, point-in-time recovery
Main API service0 minutes15 minutesRedeploy from CI, multi-AZ load balancing
S3 uploads24 hours24 hoursVersioned bucket, cross-region replica
Auth tokens store10 minutes30 minutesRe-issue tokens if needed

Once you have numbers, you can design backups and failover mechanisms to meet them.

Document Recovery Procedures

Your plan must describe step-by-step procedures for common disaster scenarios. Anyone on the team should be able to follow them.

Example for "Primary DB instance destroyed in region A":

  1. Confirm that the DB is unavailable and not simply slow.
  2. Decide whether to fail over to a replica or restore from backup.
  3. If using a replica:
    • Promote replica in region B to primary.
    • Update DB connection string in configuration / secret store.
    • Restart application instances with new configuration.
  4. If restoring from backup:
    • Provision a new DB instance in region B.
    • Restore from the latest full backup and replay WAL logs up to target time.
    • Run schema migrations if needed.
    • Update configuration and restart application.
  5. Verify application can read and write.
  6. Announce partial or full service restoration.

Write these steps in a shared document or runbook and keep them updated as the system evolves.

Data Backup Strategies for DR

Disaster recovery is impossible without reliable backups. Backups are your last line of defense against many disasters, especially logical ones.

Types of Backups

The three common backup types:

TypeDescriptionProsCons
FullComplete copy of data at a point in timeSimple, easiest to restoreLarge, slow to create
IncrementalChanges since the last backup (any type)Smaller, fast to createRestore may require many backups
DifferentialChanges since the last full backupBalance between full and incrementalGrows until next full backup

For databases like PostgreSQL, you often combine:

This allows point-in-time recovery: you restore base backup and replay logs up to a specific timestamp.

Backup Frequency and Retention

To meet your RPO, choose a suitable backup frequency.

Example:

You also need a retention policy:

Typical pattern:

Backup Rules

  • Always store backups outside the primary failure domain (for example, different region or account).
  • Treat backups as sensitive data, protect them with access control and encryption.
  • Test restoring from backups regularly. A backup that cannot be restored is useless.

Where to Store Backups

Options include:

At minimum:

Failover and Failback

Backups let you rebuild, but failover handles switching production traffic to a healthy environment. Failback is returning to normal once the disaster is over.

Failover Mechanisms

Common techniques:

  1. Database failover
    • Promote a read replica to primary.
    • Use DNS names or configuration variables so the app does not reference IPs directly.
    • Some managed databases support automatic failover, but you still need to plan for it.
  2. Application failover
    • Run application instances in multiple AZs.
    • Use a load balancer that can stop sending traffic to unhealthy instances.
    • For multi-region, use DNS-level failover (for example, health-check based).
  3. Storage failover
    • Use cross-region replicated buckets.
    • If the primary region is down, switch configuration to use the secondary bucket.

Failover must be:

DNS and Load Balancing in DR

DNS often plays a central role in DR.

Pattern:

Things to consider:

Test at least:

Failback Considerations

Once the original region or system is healthy, you may want to move back.

Challenges:

Typical steps:

  1. After crisis, treat the new primary as the source of truth.
  2. Rebuild the old primary from the new primary, either:
    • Through replication, or
    • By taking a fresh backup and restoring it.
  3. Once old primary is synchronized and acts as a replica, you can optionally promote it and redirect traffic again.

Sometimes, you decide not to fail back at all. You keep the new environment as the permanent primary.

Testing and Practicing Disaster Recovery

A disaster recovery plan that nobody has practiced is only a guess. Regular testing is crucial.

DR Drills and Game Days

You can schedule DR drills, sometimes called game days, to simulate disasters.

Examples:

Practical tips:

Measuring and Improving RPO/RTO

During drills, measure:

If actual values are worse than targets, you have two options:

Also track:

Your goal is to reduce manual, error-prone steps over time.

DR for Databases, Files, and Services

Different components need different DR techniques.

Databases

For relational databases such as PostgreSQL:

Common patterns:

In DR:

Make sure schema migrations are:

File Storage and Object Storage

User uploads such as images, documents, and logs often live in object storage.

Recommended practices:

In DR:

Note that large volumes of files can make restore slow. In many systems, user experience tolerates missing very old files better than missing recent database records.

State in Caches, Queues, and Other Services

Caches:

Message queues:

Other services such as search indexes:

Human and Process Aspects

Disaster recovery is also about people, communication, and decision making.

Roles and Responsibilities

Define who does what during an incident:

Possible roles:

You do not need a large team, but you do need clarity. Even in a small startup, you can decide that:

Communication During a Disaster

While you are recovering, users and internal stakeholders must know what is happening.

Typical communication items:

Avoid being overly optimistic. State clearly when you do not know yet and will update later.

After the incident, write a post-incident report. It should describe:

Putting It All Together

For a typical backend in this course context, a practical, minimal disaster recovery setup might look like this:

By combining solid backups, clear failover paths, and regular practice, you turn disasters from existential threats into difficult but manageable events.

Views: 8

Comments

Please login to add a comment.

Don't have an account? Register now!