0
0
DBMS Theoryknowledge~6 mins

Replication strategies in DBMS Theory - Full Explanation

Choose your learning style9 modes available
Introduction
When data is stored in multiple places, it helps keep it safe and available even if one place fails. But copying data everywhere can be tricky and slow. Replication strategies solve this by deciding how and when data should be copied between systems.
Explanation
Master-Slave Replication
In this strategy, one database acts as the master where all changes happen. The other databases, called slaves, copy data from the master but do not accept changes themselves. This keeps data consistent but can slow down if the master is busy.
Master-Slave replication copies data from one main source to others that only read.
Master-Master Replication
Here, multiple databases can accept changes and share updates with each other. This allows more flexibility and availability but requires careful conflict handling when two places change the same data at once.
Master-Master replication lets multiple databases update data and sync with each other.
Synchronous Replication
Data changes are copied to all replicas at the same time before confirming success. This ensures all copies are always the same but can slow down operations because they wait for all copies to update.
Synchronous replication keeps all copies exactly the same by updating them together.
Asynchronous Replication
Changes are sent to replicas after the main database confirms success. This is faster but means replicas might be slightly behind the master for a short time.
Asynchronous replication updates copies after the main change, allowing faster operations but temporary differences.
Real World Analogy

Imagine a teacher (master) writing notes on a board while students (slaves) copy them. In one class, only the teacher writes, and students just watch. In another, several teachers write on different boards and share notes to keep up. Sometimes, students copy notes immediately; other times, they copy later after class.

Master-Slave Replication → One teacher writes notes, and students copy without changing them.
Master-Master Replication → Multiple teachers write notes and share updates with each other.
Synchronous Replication → Students copy notes at the same time as the teacher writes them.
Asynchronous Replication → Students copy notes after the teacher finishes writing.
Diagram
Diagram
┌───────────┐        ┌───────────┐
│  Master   │───────▶│  Slave 1  │
└───────────┘        └───────────┘
      │                   ▲
      │                   │
      ▼                   │
┌───────────┐             │
│  Slave 2  │─────────────┘
└───────────┘

Master-Master:
┌───────────┐     ┌───────────┐
│ Master 1  │◀───▶│ Master 2  │
└───────────┘     └───────────┘
The diagram shows Master-Slave replication with one master sending data to multiple slaves, and Master-Master replication with two masters syncing data between each other.
Key Facts
ReplicationThe process of copying data from one database to another to increase availability and reliability.
Master-Slave ReplicationA replication method where one database handles writes and others copy data without changes.
Master-Master ReplicationA replication method where multiple databases can accept writes and synchronize changes.
Synchronous ReplicationReplication where data is copied to all replicas before confirming the operation.
Asynchronous ReplicationReplication where data is copied to replicas after the main operation is confirmed.
Common Confusions
Believing that Master-Slave replication allows slaves to accept data changes.
Believing that Master-Slave replication allows slaves to accept data changes. In Master-Slave replication, only the master can accept changes; slaves only copy data and do not accept writes.
Thinking synchronous replication is always faster than asynchronous.
Thinking synchronous replication is always faster than asynchronous. Synchronous replication waits for all copies to update, which can slow down operations compared to asynchronous replication.
Assuming Master-Master replication never has conflicts.
Assuming Master-Master replication never has conflicts. Master-Master replication can have conflicts when multiple masters change the same data, requiring conflict resolution.
Summary
Replication strategies decide how data is copied between databases to keep it safe and available.
Master-Slave replication has one main source and read-only copies, while Master-Master allows multiple writable sources.
Synchronous replication updates all copies together for consistency, whereas asynchronous replication updates copies later for speed.