Schedule icon
Query icon
Script icon
Docker icon
If icon
SlackIncomingWebhook icon
Fail icon
Log icon

MySQL Read Replica Replication Lag and Health Sentinel

Monitor MySQL read replica replication status, track IO and SQL thread health, detect replication lag breaches, and dispatch DBA alerts to Slack.

Categories
DataInfrastructure

Diagram unavailable

We could not build the topology for this blueprint. The flow itself is valid, use the YAML on the left to run it.

MySQL read replicas form the backbone of modern database scalability. However, heavy write batches, DDL locks, or network latency can cause replicas to fall severely behind the primary:

  • Stale Reads: Application queries directed to the replica return outdated or missing data, impacting user experience.
  • Dangerous Failovers: If an automated failover promotes a lagging replica during an incident, unapplied transactions are lost.
  • Silent Thread Halts: When a replication error occurs (e.g. key collision or schema mismatch), the SQL applier thread silently halts (Replica_SQL_Running: No), causing lag to accumulate indefinitely.

This blueprint provides automated, continuous replication observability for MySQL and MariaDB:

  • Queries SHOW REPLICA STATUS every 5 minutes via the MySQL JDBC plugin.
  • Automatically supports both modern MySQL 8.0+ column definitions (Replica_IO_Running, Seconds_Behind_Source) and legacy MySQL 5.7 / MariaDB columns (Slave_IO_Running, Seconds_Behind_Master).
  • Evaluates IO thread status, SQL applier status, and numeric replication delay in seconds.
  • Dispatches rich Slack incident cards when lag breaches configurable SLA thresholds or when replication crashes.

How it works

  1. scheduled_replication_check triggers recurring checks every 5 minutes (or on demand).
  2. check_replica_status executes SHOW REPLICA STATUS against the target replica instance via io.kestra.plugin.jdbc.mysql.Query.
  3. evaluate_replica_health runs a Python script to parse telemetry, normalize column differences across MySQL versions, extract error messages, and calculate lag metrics.
  4. evaluate_sla_breach (io.kestra.plugin.core.flow.If) branches:
    • If threads are stopped or lag exceeds max_lag_seconds: dispatches a Slack alert with binlog coordinates and error diagnostics, and optionally triggers fail_execution.
    • If healthy: logs in-sync verification metrics.
  5. An errors block catches connection drops or bad credentials.

What you get

  • Proactive SLA Breach Detection: Catch replication delays before users experience stale reads.
  • Cross-Version Compatibility: Works seamlessly across MySQL 5.7, MySQL 8.0+, and MariaDB.
  • Actionable Diagnostic Context: Alerts include exact binlog filenames, coordinates, and error strings for rapid troubleshooting.
  • Zero Credential Leaks: Database passwords and webhook tokens remain secured via Kestra namespace secrets.

Prerequisites

  • A MySQL (5.7+, 8.0+) or MariaDB instance configured as a read replica.
  • Database user with REPLICATION CLIENT (or REPLICATION SLAVE) privileges.
  • An incoming Slack webhook URL for notifications.

Secrets

  • MYSQL_USERNAME: Database username with replication inspection privileges.
  • MYSQL_PASSWORD: Database password.
  • SLACK_WEBHOOK_URL: Slack Incoming Webhook URL.

Quick start

  1. Add MYSQL_USERNAME, MYSQL_PASSWORD, and SLACK_WEBHOOK_URL to your Kestra namespace secrets.
  2. Configure mysql_url with your replica's JDBC connection string (e.g. jdbc:mysql://replica.internal:3306/production).
  3. Adjust max_lag_seconds to match your application's replication SLA (default: 60s).
  4. Trigger a manual execution to test initial connectivity and replication telemetry.

How to extend

  • Automated Traffic Shunting: Integrate with ProxySQL or AWS Route 53 to remove a lagging replica from the active read pool automatically.
  • PagerDuty Escalation: Add io.kestra.plugin.pagerduty.Alert alongside Slack for high-severity thread halt incidents.
  • Multi-Replica Sweep: Wrap the query task in an io.kestra.plugin.core.flow.Loop over a list of replica endpoints to audit an entire read replica cluster.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.