ClickHouse uses asynchronous multi-master replication, which means
· You can send data to any available node—it doesn’t rely on just one.
· The node saves the data first, then syncs it with other nodes in the background.
· Over time, all nodes have the same data (called "eventual consistency").
· If a node fails, ClickHouse fixes it automatically (or with minimal help in rare cases).
1. What is Multi Master Replication?
In Multi Master Replication System:
· Multiple nodes can accept write operations (inserts, updates).
· A client can send data to any available master/replica.
· After a node receives the data and stores it locally, the same data is shared with the other nodes in the background.
· Over time, all the nodes end up with the same data. This is called eventual consistency.
2. Advantages of Multi-Master Architecture in Databases
A multi-master setup allows more than one node in a database cluster to handle write operations. This design brings high availability, fault tolerance, and better performance, especially when dealing with heavy workloads or geographically distributed users.
2.1 Load Sharing Across Nodes
One of the biggest advantages of a multi-master setup is the ability to distribute write traffic across multiple nodes.
· In a single-master system, all write operations go through just one node. This can become a bottleneck as traffic grows.
· In a multi-master system, clients can send write requests to any available master node. These writes are then asynchronously replicated to the other masters, and ensure all nodes eventually hold the same data. The Multi Master system handles higher write throughput by distributing load across multiple masters.
2.2 No Single Point of Failure
If there's only one master node and it goes down, the entire system may become unavailable for writes. In a multi-master architecture, even if one master crashes, other masters continue to serve writes. This ensures high availability and reduces the risk of major downtimes.
2.3 Lower Latency Across Geographies
When your users are spread across the globe, sending every write to a central master node can cause high latency.
With a multi-master setup, you can place a master node in each major region. Clients can then write to the closest master, reducing the time it takes for a request to complete.
2.4 Graceful Upgrades and Maintenance
In systems with only one master, upgrading the software or restarting that node usually causes downtime or write unavailability.
In a multi-master setup, you can upgrade one master at a time while others continue to serve traffic. After the upgrade, replication will catch up, and the upgraded node rejoins the cluster. This model supports zero-downtime maintenance and upgrades.
3. Key Considerations in a Multi-Master Replication Strategy
3.1 Eventual Consistency
In a multi-master setup, replication between nodes is typically asynchronous, meaning that updates made on one master may take time to propagate to others. As a result, the system offers eventual consistency rather than immediate consistency. This delay can lead to temporary data inconsistencies across nodes, which causes traditional ACID guarantees (especially isolation and consistency) to be weakened or lost.
3.2 Performance Overhead
Every write operation on a master node must be replicated to all other master nodes in the cluster. This continuous data synchronization adds substantial network overhead, especially in large-scale systems, potentially leading to slow performance and reduced throughput due to bandwidth saturation and increased replication lag.
3.3 Conflict Resolution
One of the biggest challenges in multi-master replication is conflict resolution. Since all master nodes can accept writes, there’s a risk of conflicting updates on the same data item. Handling these conflicts depends heavily on the application’s business logic. Some systems may opt to discard conflicting writes, while others may follow a last-write-wins policy. Designing a robust conflict resolution strategy is crucial and often context-dependent, require a careful balance between consistency, correctness, and user expectations.
4. Multi-Master Replication vs. Primary-Replica Replication
In a primary-replica setup (also called single-master replication):
· One node, known as the primary (or master), is responsible for handling all write operations.
· The other nodes, called replicas (or slaves), are read-only copies that replicate data from the primary node.
· If a client or application wants to update data, it must send the request to the primary.
· Replicas asynchronously or synchronously copy data from the primary to ensure consistency for read operations.
Advantages Of Primary-Replica Replication
· Strong consistency is easier to achieve because only one node writes to any piece of data.
· Conflict resolution is unnecessary as there is no possibility of concurrent writes on multiple nodes.
· Simpler system design and implementation.
Disadvantages Of Primary-Replica Replication
· The primary node can become a single point of failure (unless failover is in place).
· Scalability is limited for write-heavy workloads, since only one node handles all the writes.
· Higher latency for writes if clients are geographically distant from the primary node.
The choice between primary-replica and multi-master replication depends on application requirements.
Use primary-replica when
· You need strong consistency.
· Your system is read-heavy.
· Simplicity is preferred.
· Conflict resolution is hard to implement.
Use multi-master when
· You need high availability and low latency for distributed clients.
· Your application can tolerate eventual consistency.
· You’re ready to implement and handle conflict resolution logic.
5. Multi-Master Replication vs. Failover Clustering
In failover clustering,
· Only one node (the master) is active and handles all client requests, including reads and writes.
· Other nodes (the passive replicas) do not serve client requests, instead, they synchronize data from the master, keeping themselves up-to-date.
· These passive nodes are on standby, ready to take over automatically if the active master fails.
· The system usually includes a cluster manager or watchdog process that monitors the health of the master. If the master fails, the manager promotes a passive replica to become the new master.
Advantages Of Failover Clustering
· Simple conflict-free architecture, since only one node processes all operations.
· Automatic failover reduces downtime.
· Useful in mission-critical systems where downtime must be minimized.
Disadvantages Of Failover Clustering
· No active-active support; resources of standby nodes remain underutilized until failover.
· Potential for write downtime during failover transitions.
Previous Next Home
No comments:
Post a Comment