Skip to main content

Running MySQL Clusters Under Production Traffic: Practical SRE Notes

· 3 min read
Ilham Surya
Platform Engineer (Engineering Infra) - SRE & Agentic AI - Go, Python, TypeScript

Managing MySQL in local development is forgiving. Running a MySQL cluster under live production traffic—especially during sudden campaign spikes—is where small oversights turn into outages fast.

Here are the core operational habits I rely on to keep MySQL clusters fast, predictable, and recoverable in production.

1. Topology & Read/Write Discipline​

Most high-traffic workloads start with a Primary + Read Replicas setup (or multi-AZ managed RDS/cluster deployments):

  • Route heavy reporting and read-only lookups to replicas, keeping the primary focused on writes and strongly consistent reads.
  • Watch replication lag closely. If a replica falls seconds behind during a batch job, reads immediately after writes can return stale data—critical read-after-write flows should stay pinned to the primary.
  • Never run unbounded DELETE / UPDATE backfills in one transaction. Chunk large migrations into small batches (e.g., 1,000–5,000 rows with brief sleeps) so you don't lock hot tables or spike replication delay.

2. Connection Pooling & Pool Sizing​

One of the fastest ways to take down a MySQL cluster during a traffic surge is connection exhaustion from horizontally scaled Go/Python microservices:

  • Always configure explicit max open connections, idle connections, and connection lifetime per service instance.
  • Calculate worst-case connections as max_pods × pool_size and verify it stays safely under MySQL's max_connections with headroom for admin/monitoring access.
  • Use a proxy layer (like ProxySQL or RDS Proxy) when dozens of short-lived pods or serverless workers share the same cluster.

3. Slow Query Triage & Indexing​

Before scaling up hardware, check the query plan—90% of MySQL CPU spikes come from a handful of unindexed queries:

  • Keep slow_query_log enabled with a sensible long_query_time (e.g., 0.5s–1s) and aggregate patterns regularly.
  • Run EXPLAIN ANALYZE on every new production query touching large tables—watch out for full table scans (type: ALL), Using filesort, and implicit type casts that silently bypass indexes.
  • Design composite indexes with equality columns first and range/sort columns last, and avoid over-indexing write-heavy tables (every extra index slows down INSERT/UPDATE).

4. Metrics That Actually Catch Trouble Early​

In Grafana / Prometheus (mysqld_exporter), I focus on a tight set of leading indicators rather than noisy dashboards:

  • Threads Running (a sudden spike signals lock contention or slow queries faster than CPU alone)
  • InnoDB Buffer Pool Hit Ratio & Dirty Pages
  • Replication Lag (Seconds_Behind_Master)
  • Lock Waits & Deadlocks per second
  • Disk IOPS & Free Storage Headroom (running out of disk on binlogs is completely avoidable with retention policies and alerts at 70%/85%)

5. Backups & Failover Drills Aren't Optional​

A backup you have never restored is just a hope:

  • Combine scheduled full snapshots + binlog retention for Point-in-Time Recovery (PITR).
  • Practice replica promotion and failover in staging periodically so the team knows exact DNS/endpoint switchover times and verifies that application connection pools reconnect cleanly without manual restarts.