Skip to content
Author: ytianle

Database Replication⚓︎

Database replication is the process of copying and maintaining database objects, such as tables, in multiple database servers.

The core goal of DB replication is:

  1. High Availability: Ensure that data is accessible even if one server fails.
  2. Fault Tolerance: Minimize data loss and downtime during failures.
  3. Load Balancing: Distribute read and write operations across multiple servers to improve performance.

Types of Database Replication (By Architecture)⚓︎

  1. Master-Slave Replication: In this architecture, one server (the master) handles all write operations, while one or more servers (the slaves) handle read operations. Changes made to the master are asynchronously replicated to the slaves. MongoDB and MySQL commonly use this architecture.
  2. Multi-Master Replication: In this setup, multiple servers can handle both read and write operations. Changes made on any server are replicated to all other servers. This architecture provides higher availability and load balancing but requires conflict resolution mechanisms. DynamoDB and CouchDB commonly use this architecture.
  3. Masterless Replication: In this architecture, all servers are equal and can handle both read and write operations. Changes made on any server are propagated to all other servers. This architecture is more complex to implement but provides high availability and fault tolerance. Cassandra and Riak commonly use this architecture.

alt text

Methods of Database Replication (By Technique)⚓︎

  1. Synchronous Replication: In this method, changes made to the primary database are immediately replicated to the secondary databases. This ensures data consistency but can introduce latency, as the primary database must wait for confirmation from the secondary databases before completing a transaction.
  2. Asynchronous Replication: In this method, changes made to the primary database are replicated to the secondary databases after a delay. This r^^educes latency but can lead to data inconsistency^^ if the primary database fails before the changes are replicated.

alt text

Specialized Replication Techniques in SQL Databases⚓︎

  1. Snapshot Replication: This technique involves taking a "snapshot" of the entire database at a specific point in time and copying it to another server. It is useful for initial data synchronization or when data changes infrequently.
  2. Transactional Replication: This method captures and replicates individual transactions from the primary database to the secondary databases. It ensures that changes are applied in the same order as they occurred, maintaining data integrity. (ACID properties)
  3. Merge Replication: This technique allows changes to be made on multiple servers, which are then merged together. It is useful for scenarios where data can be modified independently on different servers, such as in distributed applications.

References⚓︎