When read traffic on your primary ApsaraDB RDS for MySQL instance becomes a bottleneck, read/write splitting lets you distribute read requests across the primary instance and multiple read-only instances — without changing your application code. Write traffic always goes to the primary instance.
How traffic is routed
All routing is transparent to the application. You set the read weight for each instance in the console, and PolarDB-X 1.0 distributes traffic accordingly.
| Request type | Destination | Consistency |
|---|---|---|
| Write (INSERT, REPLACE, UPDATE, DELETE, CALL) | Primary instance | Strong (real-time) |
| Read outside an explicit transaction (SELECT, SHOW, EXPLAIN, DESCRIBE) | Primary or read-only instances, by weight | Strong (primary) or weak (read-only) |
| Read inside an explicit transaction | Primary instance | Strong (real-time) |
Consistency trade-off for read-only instances
Reads from read-only instances are weakly consistent. Data is replicated asynchronously from the primary instance with millisecond-level latency, so a read-only instance may return slightly stale data.
If a query requires real-time, strongly consistent data, use a hint to route it to the primary instance. For details, see Read/write splitting.
Transaction behavior
Read/write splitting applies only to read requests that are not inside an explicit transaction.
An explicit transaction is one that must be explicitly committed or rolled back. All statements inside an explicit transaction — including read-only transactions and SELECT statements — run on the primary instance and are not distributed to read-only instances.
When read/write splitting does not apply
Read/write splitting has no effect in the following situations:
The query is inside an explicit transaction (committed or rolled back manually).
The query is a write statement (INSERT, REPLACE, UPDATE, DELETE, CALL).
You use a hint to force the query to the primary instance.
In these cases, all traffic goes to the primary instance.
What's next
To enable read/write splitting and configure read weights for each instance, see Storage management.