> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Replication vs Backup

> Describes differences between database replication and backups, their roles, limitations, and best practices for recovery and data protection

You should never confuse database replication with database backups. Both are essential, but they solve different problems: replication provides availability and scalability, while backups provide data protection and the ability to recover from accidental or malicious changes.

Replication and backups are complementary. Design your system so replication keeps services online and responsive, and backups let you recover the correct data when something goes wrong.

When you run a production database, a common best practice is to maintain at least two replicas for the primary. In a typical configuration there are three copies of the data on separate machines: one primary and two replicas. Replicas keep persistent connections to the primary and continuously copy changes, staying up to date with near-real-time replication.

![A stylized diagram titled "REPLICATION vs BACKUP" showing a primary database connected by persistent links to two replica databases on separate machines. Users at the top send queries to the primary, with teal cylinder icons and arrows illustrating the replication flow.](https://mintcdn.com/kodekloud-c4ac6d9a/IK4ISE2GFis3psR1/images/DevOps-Interview-Questions-and-Answers-Scenario-Based-Prep/Databases/Replication-vs-Backup/replication-vs-backup-primary-replicas.jpg?fit=max\&auto=format\&n=IK4ISE2GFis3psR1\&q=85\&s=859ff89b12459727fb06a7f6e02c4d96)

## How replication helps (and where it stops)

Replication is primarily about high availability and read scaling:

* Failover: If the primary fails, a replica can be promoted to primary quickly, minimizing downtime.
* Read scaling: Replicas can serve read-only queries to reduce load on the primary.
* Low-latency copies: Replication keeps near-real-time copies of the live dataset.

However, replication faithfully streams everything that happens on the primary — including mistakes, schema changes, and data corruption. For example, a destructive operation on the primary will be applied to all replicas immediately:

```sql theme={null}
DELETE FROM orders;
```

Replication propagates all changes from the primary to replicas, including human errors, application bugs, or corruption. Replication ensures uptime and read scaling, not protection against data loss caused by destructive changes.

## Why backups are necessary

Backups are periodic snapshots or archived copies of your data stored separately from the live system (offsite and ideally immutable). Backups allow you to restore to a previous point in time, undoing destructive operations or recovering from data corruption that replication would otherwise repeat across replicas.

Key recovery concepts:

* RTO (Recovery Time Objective): How long it can take to restore service.
* RPO (Recovery Point Objective): How much data loss (time) is acceptable.

## Quick comparison

| Feature | Replication | Backups |
| - | - | - |
| Purpose | High availability, failover, read scaling | Data protection and recovery |
| Timeframe of data | Near real-time copy | Snapshot at a point in time or series of increments |
| Protection against accidental deletes | No — mistakes are propagated | Yes — you can restore to a point before the mistake |
| Typical storage location | On other database nodes (same cluster) | Offsite or immutable storage (object store, tape, etc.) |
| Use case example | Promote replica as primary after hardware failure | Restore data after accidental DELETE or ransomware |

## Backup best practices

* Mix full and incremental backups to balance speed and storage.
* Enable point-in-time recovery (PITR) when supported by the database engine (e.g., PostgreSQL WAL archive).
* Store backups off-cluster and offsite; use immutability and versioning to prevent accidental deletion.
* Test restores regularly to validate backups and recovery processes.
* Define retention policies that meet legal and business requirements.
* Automate backup monitoring and alerting for failures or long-running jobs.

Table — Practical checklist

| Task | Why it matters | Example/Notes |
| - | - | - |
| Regular full backups | Fastest to restore and baseline data | Weekly full backup + daily incremental |
| Incremental or differential | Saves storage and speeds up backups | Use WAL/transaction log archiving for PITR |
| PITR enabled | Restore to a specific time before an incident | See database docs for WAL/backup configuration |
| Offsite storage | Protect against site-wide disasters | Object storage with versioning (S3, GCS) |
| Immutable backups | Prevent tampering / ransomware | WORM/retention policies or write-once storage |
| Restore testing | Ensure recoverability and reduce surprises | Quarterly restore drills in staging |

## Recovery workflow (high level)

1. Identify scope and time of the data loss (which tables, timestamp).
2. Choose recovery method: restore full backup + apply transaction logs (PITR) or restore a backup snapshot.
3. Restore into an isolated environment to verify the dataset before promoting to production.
4. Validate integrity and consistency, then fail over production traffic only when confident.

## In short

* Use replication for high availability and read scaling.
* Use backups for data protection and recovery from accidental/malicious changes or corruption.
* Both are necessary for a robust production system — replication keeps services online, backups let you recover correct data.

## Links and further reading

* [PostgreSQL: Continuous Archiving and Point-in-Time Recovery](https://www.postgresql.org/docs/current/continuous-archiving.html)
* [AWS RDS Backups and Automated Backups](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_WorkingWithAutomatedBackups.html)
* [Database backup strategies (general guidance)](https://en.wikipedia.org/wiki/Database_backup)

> [card] [Watch Video](https://learn.kodekloud.com/user/courses/devops-interview-prep/module/1ee75c71-d566-42df-8cc2-7aa8e79b0f04/lesson/b7f53bf4-b40c-4436-8522-04502399449a)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.