Get the App
SLTechnology News&Howtos  ›  Database  › 

MYSQL MONGODB REDIS synchronization principle and High availability comparison

Shulou Source: shulou.com Published: 2022-06-01 07:23:36 09月27日 Update

MySQL

1. Asynchronous replication:

2. Semi-synchronous replication: when synchronization times out, it automatically changes back to asynchronous replication.

MongoDB

A replica set of MongoDB is a collection of mongod processes that provide redundancy and high availability. The smallest replica set contains (1 primary, 1 secondary, and 1 arbiter), and most deployments contain 3 nodes (1 primary, 2 secondary). A replica set can support up to 12 nodes, and a master-slave architecture is required for more than that.

Primary: receives all write operations from clients. There can be only one primary per replica set, and in order to support data replication, all operations of the primary to change the data are recorded in the oplog.

Secondary: maintain data consistency with primary (asynchronous with latency) by copying primary's oplog and replaying oplog. When the master is not available, the replica set selects one of the secondary as the primary. By default, all read operations will also point to primary, but you can configure read operations to point to secondary (data strict consistency cannot be guaranteed due to latency in copying data). You can configure priority to make null values become the priority of primary, priority=0 means that you cannot become primary, and you can also configure hidden replica members.

Arbiter:arbiter does not store data, it is only used to elect primary. When the cluster has an even number of nodes, add an artiber to get the secondary with the most votes as the primary. Arbiter does not require special hardware.

Replica Set Elcetions: during the election process, the replica set does not take over the write operation because there is no primary, and all members are read-only. If most of the members of the replica set are not available, the replica set will not select primary.

Heartbeats: replica set members send a heartbeats (pings) to other members every 2 seconds. If a heartbeat does not receive a response for 10 seconds, the sender of the heartbeat will mark the receiver of the heartbeat as unreachable.

Replica set features: asynchronous, automatic failover

You can set up a function similar to MySQL semi-synchronization, which can specify how many nodes will return after completing the write synchronization, and there is a timeout.

A typical replica set structure

Redis

Comparison between MySQL and MongoDB

There is semi-synchronous replication in MySQL and semi-synchronous replication in MongoDB.

Tags: Copy synchronization data member node configuration can pass point to time guarantee support election availability minimum special consistent consistent master-slave priority even number Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL NVidia Shulou Tech Info Huawei Microsoft