Database Replication in System Design (original) (raw)

Last Updated : 10 Dec, 2024

Database replication is essential to system design, particularly when it comes to guaranteeing data scalability, availability, and reliability. It involves building and keeping several copies of a database on various servers to improve fault tolerance and performance.

Database-Replication-in-System-Design

Table of Content

What is Database Replication?

Making and keeping duplicate copies of a database on other servers is known as database replication. It is essential for improving modern systems’ scalability, reliability, and data availability.

Importance of Database Replication

Database replication is important for several reasons:

How does Database Replication works?

Here are the steps explaining how database replication works:

Types of Database Replication

Let’s understand the different types of database replication:

  1. **Master-Slave Replication:
    • The process of copying and synchronizing data from a primary database (the master) to one or more secondary databases (the slaves) is known as master-slave replication.
    • In this configuration, all write operations, including inserts, updates, and deletions, must be received by the master database.
    • The slave databases keep a duplicate of the data and replicate the modifications made to the master database.
  2. **Master-Master Replication/Multi-Master Replication:
    • Master-master replication, also known as bidirectional replication, is a setup in which two or more databases are configured as master databases, and each master can accept write operations.
    • This means that changes made to any master database are replicated to all other master databases in the configuration.
  3. **Snapshot Replication:
    • Creating a copy of the whole database at a certain moment in time and then replicating that snapshot to one or more destination servers is known as snapshot replication.
  4. **Transactional Replication:
    • One way to maintain several copies of a database synchronized in real-time is through transactional replication.
    • This means any modifications made to a particular table (or group of tables) in one database—referred to as the publisher—are instantly copied to other databases—referred to as subscribers.
  5. **Merge Replication:
    • Merge replication is a database synchronization method allowing both the central server (publisher) and its connected devices (subscribers) to make changes to the data, resolving conflicts when necessary.

Strategies for Database Replication

Database replication strategies determine how to select data, copy and distribute it between databases to gain specific goals such as scalability, availability, and efficiency. Some common database replication strategies include the following:

Configurations of Database Replication in System Design

To accomplish particular objectives related to data consistency, availability, and performance, database replication can be set up and run in a variety of ways:

  1. **Synchronous Replication Configuration:
    • It is a database replication technique that replicates data changes in real-time to one or more replicas. Until at least one copy acknowledges receiving the changes, the transaction isn’t considered committed.
    • This technique offers a high degree of data consistency by guaranteeing that the main database and replicas of it are constantly in sync.
  2. **Asynchronous Replication Configuration:
    • Data changes performed on the primary database are replicated to one or more replicas using this database replication technique, which does not wait for the clones to acknowledge them.
    • Faster transaction processing on the primary database is possible with this approach, but there may be a small lag in data consistency between the primary and replica(s).
  3. **Semi-synchronous Replication Configuration
    • A database replication technique called semi-synchronous replication combines elements of synchronous and asynchronous replication.
    • While other copies are updated asynchronously for improved efficiency, semi-synchronous replication ensures excellent data consistency for essential data by replicating changes to at least one replica synchronously.

**Challenges with Database Replication

Somw of the challenges with Database Replication are: