ApsaraDB RDS for MySQL implements read/write splitting
Read/write splitting routes write traffic to the primary instance and read traffic to read-only instances through a single proxy endpoint. This lets you scale read capacity horizontally without changing your application's connection string.
How it works
ApsaraDB RDS for MySQL implements read/write splitting through the database proxy. When your application connects to the proxy endpoint instead of the primary instance endpoint, the proxy inspects each incoming connection and routes it automatically:
-
Write operations (INSERT, UPDATE, DELETE, DDL) go to the primary instance.
-
Read operations (SELECT) are distributed across available read-only instances.
The proxy balances load at the connection level, not the query level. A single persistent connection always routes to the same backend instance. To distribute reads across multiple read-only instances, open separate connections for separate read workloads—or use a connection pool that opens multiple connections to the proxy endpoint.
Read-only instances use asynchronous replication. There is always a measurable replication lag between the primary instance and its read-only instances. Avoid routing queries that require the latest committed data to read-only instances—for example, reading a row immediately after writing it in the same session. Use the primary instance endpoint directly for those operations.
When to use read/write splitting
Read/write splitting is a good fit when:
-
Your workload is read-heavy—most queries are SELECT statements, and the primary instance CPU or I/O is a bottleneck.
-
You have already added one or more read-only instances and want to use them without managing separate connection strings in your application.
-
You want to offload reporting or analytics queries from the primary instance without affecting transactional throughput.
Read/write splitting does not reduce write load. All INSERT, UPDATE, DELETE, and DDL statements still execute on the primary instance. If write throughput is the bottleneck, read/write splitting will not help.
Prerequisites
Before you begin, ensure that you have:
-
An ApsaraDB RDS for MySQL primary instance
-
At least one read-only instance attached to the primary instance
-
The database proxy feature enabled on the instance
Enable read/write splitting
To enable read/write splitting, enable the proxy terminal feature and configure the proxy endpoint as the application's connection target. For step-by-step instructions, see Enable the proxy terminal feature for an ApsaraDB RDS for MySQL instance.
What's next
After enabling the proxy terminal feature, update your application's connection string to point to the proxy endpoint. The proxy endpoint accepts the same credentials as the primary instance—no additional account configuration is required.