Using Leader-Follower Topology for Availability

Page last updated:

This topic describes how to use the leader-follower topology for the MySQL service.

You can maintain availability of your MySQL databases by keeping two copies of your database, one on a leader (master) instance and another on a follower (slave) instance. If the leader instance fails due to hardware or software issues or during a period of planned maintenance, you can initiate a failover of apps to the follower instance. This helps minimize downtime for apps that bind to your MySQL databases.

For more information, see:

Leader-Follower Setup and Failover Process

The following are the high-level steps for setting up and using a leader-follower topology, and for initiating a failover.

Leader-Follower Setup

  1. The operator configures a leader-follower plan. See Configure a Leader-Follower Service Plan below.

  2. Developers create an instance from the leader-follower plan. Doing this automatically deploys two MySQL VMs in a leader-follower topology. See Create a Service Instance.

  3. By default, data is asynchronously replicated. However, developers can enable data to synchronously replicate. For more information, see About Synchronous Replication.

  4. Developers bind apps to the leader in the leader-follower plan instance, using the leader’s IP address. Data is written to the leader and asynchronously replicated on the follower. See Bind a Service Instance to Your App.

Failover Process

  1. Promotion: If the leader instance fails or the operator wants to take the leader offline for maintenance, the operator promotes the follower instance to the new leader.

  2. Failover: After a promotion, the developer unbinds the app from the leader-follower service instance and then rebinds it in order to fail the app over to the new leader. See Triggering a Leader-Follower Failover.

Configure a Leader-Follower Service Plan

You can configure up to nine leader-follower service plans.

After you configure the leader-follower plan, it is available in the Marketplace. When a developer creates a leader-follower service instance, a leader VM is automatically deployed in one availability zone (AZ), and a follower VM is deployed in another AZ.

To configure a leader-follower service plan, do the procedure in Configure Service Plans and select Leader-Follower.

Monitor Leader-Follower Instances

In order to decide if a failover is needed, you must monitor leader-follower instances.

In monitoring the leader-follower VMs, pay attention to the following metrics:

  • /p.mysql/available: This metric records whether the MySQL VMs are responding to requests. Values are either 1 (available) or 0 (not available).

  • /p.mysql/follower_seconds_since_leader_heartbeat: Whenever the leader VM emits a heartbeat, the heartbeat is written to the leader database and replicated to the follower. This metric measures the number of seconds that elapses between the leader heartbeat and the replication of the heartbeat in the follower database, so you can determine how far behind the follower is from the leader. Normal values for this metric depend on your apps.

  • /p.mysql/follower_seconds_behind_master: The follower VM copies database writes from the leader VM, but takes time to apply them to its own database. This metric measures how far behind the follower VM is in applying these writes. For example, a follower VM may have copied writes from the leader VM that are timestamped up to 4:00pm, but it has only applied writes up to 1:00pm. Normal values for this metric depend on your apps.

For more information, see KPIs for MySQL Service Instances in Monitoring and KPIs.