Core Concepts
Disaster Recovery
Restore a useful service from independent copies and measure how much data and time the recovery cost.
Disaster recovery brings a service back after a failure its live systems cannot recover from. Decide how much data you can lose and how long the service can be down. When a bad delete has reached every live copy, you need a restore point from before the delete.
Decide what recovery must deliver
In this URL Shortener example, an accidental delete removes a group of PostgreSQL mappings, including notes. The standby applies it too. At 10:20, when the delete happens, we stop redirect and create traffic while we recover the mappings. The team would accept losing at most five minutes of recent changes and wants the shortener usable again within 30 minutes. These are illustrative targets for this extension of the walkthrough. AWS on setting recovery objectives
The recovery point objective (RPO) is the most data loss the team can accept, expressed as time. Here the usable restore point must be no more than five minutes before the interruption. The recovery time objective (RTO) is the most downtime the team can accept. Here the clock starts when the shortener stops serving, and ends when users can create links and get the right redirects again. Copying files or starting a database completes only part of that work.
Set objectives for the behavior users need back. The mappings may need to return before an analytics dashboard does. If the service relies on another database to show ownership, its recovery point and restore time need to fit the same user-facing path.
Keep something that the bad change cannot erase
Replication lets another server follow the writer. That helps after hardware loss when a suitable replica still has the right history. It also carries valid-but-unwanted changes such as our deletion to the standby. A backup preserves a recoverable older state. Keep a usable backup version and the changes needed to restore it outside the failure you want to survive. A copy in a separate site can survive loss of the primary site. Protection against account mistakes needs deletion controls and recovery access that do not depend on that same account.
PostgreSQL point-in-time recovery (PITR) combines a base backup, a copy of the database files that can serve as the starting state, with archived write-ahead log (WAL) records that describe later changes. In our example the backup completed around midnight. The replacement restores it and applies the recorded changes up to the last verified clean point at 10:19. The archive may also contain the delete. Pick the stopping point so recovery does not apply it. A gap in the archived log can stop recovery from reaching the chosen point. PostgreSQL continuous archiving and point-in-time recovery
The backup job's schedule is only one input to the achievable RPO. Check how far the archive in the recovery location actually extends and how long a usable recovery chain is retained. If an older backup is needed because damage went unnoticed for days, the retention policy must cover that period. If legitimate creates arrived after the clean point, reconcile them from a trusted source before reopening or account for the loss. Replaying everything after the clean point would bring the delete back as well.
Measure to the point users can return
The replacement database is restored at 10:34. The application still has to connect, confirm the recovered data, and take traffic. It starts serving verified requests at 10:44. In this exercise, the recovered state is one minute before the outage. The downtime is 24 minutes. Both are within the five-minute RPO target and the 30-minute RTO target.
Those results describe this run. Track time spent discovering the failure, getting credentials, restoring data, rebuilding dependencies, and moving traffic. If most of the time goes to starting the recovery stack, a warm standby can keep some of that stack ready. It costs more to run and still needs an independent recovery point for data corruption. Choose preparation based on the clock that failed in a realistic drill. AWS recovery strategies
Prove that the restored service works
Run a drill in an isolated environment using the backups, credentials, and encryption keys that would be available if the source site were down. Restore the application configuration too. A database can start successfully while the service has no permission to read it or no way to reach it.
Check a known short link against the expected 302 and destination. This exercise adds a private lookup for the saved link. Confirm that its owner can read it and that another account cannot. In the isolated environment, create a test link and retry it so you can check that the retry still yields one mapping. Start the redirect cache empty or rebuild it from the recovered database. Old cache entries can refer to mappings newer than the restored point. Bypass the redirect path's Bloom-filter negative checks until the filter has been rebuilt and verified against the recovered mappings. An incomplete filter can cause the service to return 404 for a restored link. AWS on testing data recovery
Keep the steps in a runbook that operators can access during the outage. Record the chosen point, verification results, and how long each step took. Rehearse with realistic data volume and one source dependency deliberately unavailable, such as the primary environment's key service. That tests whether the recovery copy is independent in practice.
See also
- Data Replication explains why a live copy can carry the primary's latest changes, including a deletion.
- Write-Ahead Log explains the change history PostgreSQL needs to replay.
- Object Storage (S3) explains the object store that can hold archives and how applications refer to stored objects.
- Failover transfers service to a qualified live copy when the expected data is already available there.
Used in
- URL Shortener keeps durable link mappings in PostgreSQL and serves hot redirects from Redis. The restore exercise here extends that split.
- ChatGPT moves older reply text into object storage and keeps metadata in PostgreSQL. A restore plan for history would have to preserve those references and the objects they name.
Done reading? Mark it so it sticks in your dashboard.