Replication
What is Replication?
Replication is the ability for an RDBMS to synchronize a primary server with one or more read replicas. In this configuration, the primary database serves reads and writes while the replicas only serve reads.
How to use Replication
Replication is used for disaster recovery and to increase read throughput by distributing read load.
For disaster recovery, if your primary server goes offline, your database can still serve read traffic from its replicas. Often a manual or automated process can elect and configure a replica to be the primary instance limiting downtime.
To increase read throughput, multiple replicas can be used to scale reads horizontally. If you have N replicas and your primary still takes reads, each read replica serves 1/N+1 percent of the read traffic. Note, in this set up your application must be aware of the replicas. The database does not route requests automatically.
Differences between MySQL Replication and Dolt Replication
MySQL supports multiple types of replication, most based on the MySQL binary log. Dolt supports a MySQL binlog replication mode, where you configure a Dolt sql-server as a replica for an existing MySQL or MariaDB database. Dolt does not create binary logs and can NOT act as a primary for binlog replication.
Dolt supports two replication modes where Dolt can act as a primary and replicate to other Dolt sql-servers. The first is called Remote-Based Replication. In this mode the primary and the read replicas are completely decoupled. The primary and the read replicas leverage a shared, Git-style remote to facilitate replication. On the primary, you configure "push on write" and on the replicas you configure "pull on read". This mode only replicates branch heads, which means that new dolt commits are required in order to replicate writes.
The second mode is called Direct-to-Standby Replication. In this mode, you configure a cluster of dolt sql-server instances to replicate all writes to each other. Each server is configured to replicate writes to all other servers in the cluster. One server is configured as the primary replica and it accepts writes. All other servers are configured as standbys and only accept read requests.
Interaction with Dolt Version Control
Dolt uses remotes to synchronize between primary and read replicas. Replication leverages Dolt's ability to produce differences between two versions of a database quickly.
Example
The following example shows write replication from a primary and read replicas using a Git-style remote to rendezvous and maintain loose coupling. For more details on clustering in sql-server, see the documentation for sql-server replication.
Configuring a Primary
In this example I use a DoltHub remote to facilitate replication. I created an empty database on DoltHub and configured the appropriate read and write credentials on this host.
The changes are pushed to the remote.
Configuring a Replica
To start a replica, you first need a clone.
Now, I'm going to configure my read replica to "pull on read" the main
branch from origin.
Now on the primary.
And back to the replica.
Last updated