Skip to content

Checking your reading list…

Retry verification

Stay curious. Build better.

Appearance

Choose how BestHub looks on this device.

Changes apply immediately.

Search articles

Open Discover with these filters

Suggested searches

Read-Write Separation in 7 Chinese Databases: Implementation Mechanisms Compared
Databases 18 min read

Read-Write Separation in 7 Chinese Databases: Implementation Mechanisms Compared

This article analyzes how seven major Chinese databases — OceanBase, PolarDB, GaussDB, GoldenDB, TDSQL, OpenGauss, and TiDB — implement read-write separation, detailing their proxy architectures, routing policies, consistency models, and failure handling strategies.

Overview

In high-availability database deployments with one primary and multiple replicas, read-write separation allows replicas to serve read traffic, improving resource utilization and reducing primary load. Key challenges include leveraging replica resources, preventing operational queries from spiking primary CPU, handling replication lag, and maintaining transaction consistency when writes go to the primary and reads to replicas.

1. OceanBase

OceanBase implements read-write separation via ODP (OceanBase Database Proxy). It supports separation down to the table partition level, a benefit of its native distributed architecture. Enabling it requires two steps:

Mark SQL as weak read : Weak reads do not require the latest data. By default SQL uses strong reads. Weak reads can be set per statement with the hint /*+READ_CONSISTENCY(WEAK)*/ or globally via the OBProxy config obproxy_read_consistency = 1 (0 = strong, 1 = weak). SQL hints are statement-level; the config is instance-level. Multiple OBProxy instances can be deployed, with some configured for weak reads to serve operational queries.

Adjust routing policy : The config proxy_route_policy controls replica selection for weak reads: follower_first: Prefer replicas; fall back to primary if all replicas unavailable. follower_only: Use only replicas; disconnect client if none available.

Choice depends on business tolerance for staleness and availability.

2. PolarDB (MySQL)

PolarDB's built-in read-write separation is configured in the console with two modes: read-only and read-write (auto split) . In read-write mode, writes go to the primary; reads are routed based on each node's current unfinished request count (active connections). The middleware maintains connections to all nodes and selects nodes per session based on replication sync status, ensuring post-write reads return correct results.

Additional controls:

Primary can be set to reject ordinary reads; only transactional reads with consistency requirements go to primary.

If all replicas fail, reads fall back to primary.

Health checks automatically exclude nodes that are down or exceed replication lag threshold (global consistent read timeout, 0–60000 ms, default 20 ms). Repaired nodes are re-added automatically.

2.1 Request Forwarding Rules

Primary only : DML/DDL, all transactional requests (without transaction splitting), custom functions, stored procedures.

Replica or primary : Non-transactional reads, COM_STMT_EXECUTE.

All nodes : System variable changes, COM_STMT_EXECUTE.

2.2 Weight-Based Dynamic Load Balancing

Initially only active-request-count balancing was supported. Later versions added weight-based dynamic balancing: each node gets a weight; routing considers both weight and concurrent requests. Higher weight = higher priority = more traffic. Weights configured in the console under "Database Proxy Service Configuration".

3. GaussDB (for MySQL)

After creation, read-write separation is enabled via a proxy address. Writes route to primary; reads distribute by configured read weight ratio or active connection count. Transactional requests always go to primary. Non-transactional reads offer no consistency guarantee; businesses needing read consistency can wrap reads in transactions and use transaction splitting to route pre-write reads to replicas.

Proxy configuration includes:

Proxy mode : Read-write or read-only (read-only rejects DDL/DML/temp tables).

Consistency level : Eventual consistency (default) or session consistency (guarantees each read in a session sees the latest write).

Routing mode : Weight-based load or active-connection load balancing.

SQL hints can suggest routing: /* FORCE_MASTER */ for primary, /* FORCE_SLAVE */ for replicas. Hints are advisory; non-read-only SQL or transactional contexts cannot be forced to replicas.

4. GoldenDB

Routing combines instance-level port configuration and statement-level hints.

Instance-level : Service port config — disable separation, local-city strategy (with weights), or cross-region strategy.

Statement-level : Hints READMASTER, READBALANCE, READSLAVE.

A combination matrix defines final routing. Replicas exceeding a configured lag threshold are excluded regardless of weight. New versions add a "primary readable" toggle: if disabled, reads won't go to primary even when replicas lag. In multi-shard instances, setting CN parameter force_read_split with read-write separation enabled and an explicit transaction started makes the transaction read-only; any write attempt returns "read-only transaction" error.

5. TDSQL (for MySQL)

Default read-write separation with three configuration methods for non-read-only accounts (controlled by gateway.mode.single_backend.rw_split):

Read-only accounts : Created as read-only; reads routed per replica strategy:

Strategy 1: Prefer replicas; if all exceed lag threshold, read from primary.

Strategy 2: Replicas only; error if all exceed threshold.

Strategy 3: Replicas only, ignore lag (used for binlog sync).

Slave hint : With rw_split=1, add /*slave*/ hint (lowercase, no spaces) to send specific SQL to replica. Requires MySQL client -c flag to parse comments.

Global auto split : rw_split=2 sends all reads to replicas. Lag may cause stale reads. Transactional reads or autocommit=0 with explicit begin/commit/rollback go to primary.

Official recommendation: use methods 1 and 2; method 3 incurs performance overhead.

6. OpenGauss

Read-write separation via JDBC connection properties. The targetServerType parameter in the JDBC URL controls node selection:

master</strong>: Connect to primary; fail if none.</li><li><code>slave</strong>: Connect to replica; fail if none.</li><li><code>preferSlave</strong>: Prefer replica; fallback to primary.</li><li><code>any</strong>: Any node (default).</li></ul><p>Example URLs:</p><pre><code>jdbc:opengauss://node1,node2,node3/database?autoBalance=roundrobin&targetServerType=preferSlave

On primary failure, OpenGauss uses autonomous primary discovery. JDBC parameter hostRecheckSecond (default 10s) triggers re-check of primary status after changes, enabling fast reconnection to the new primary. Connection flow: enable targetServerType ; validate candidate hosts against hostStatusMap with 10s TTL; query node status; return matching connection for read/write.

7. TiDB

Read-write separation via Follower Read , offloading TiKV read load from Region leaders to followers. Controlled by variable tidb_replica_read (session or global): leader (default): All reads to leader. follower: All reads to follower. leader-and-follower: Load balance across leader and followers. prefer-leader: Prefer leader; switch to follower if leader slows (disk/network jitter). closest-replicas: Prefer same-AZ replica (leader or follower); fallback to leader if none. closest-adaptive: If estimated result size ≥ tidb_adaptive_closest_read_threshold, prefer same-AZ replica. learner: Read from learner; error if none exists.

Follower Read uses the Raft ReadIndex protocol to ensure followers can read data already committed on the leader. TiDB only needs to route Region read requests to followers per the load-balancing policy.

8. Summary Comparison

The article includes a comparison table (image). Overall, PolarDB, GaussDB, and GoldenDB provide more comprehensive read-write separation , addressing instance-level and SQL-level controls, transaction impact, and handling when replication lag exceeds thresholds.

References:

OceanBase docs: https://www.oceanbase.com/docs/common-oceanbase-database-cn-1000000000819334

PolarDB guide: https://help.aliyun.com/zh/polardb/polardb-for-mysql/user-guide/read-or-write-splitting-2

GaussDB manual: https://support.huaweicloud.com/usermanual-gaussdbformysql/gaussdbformysql_11_0017.html

GoldenDB docs: https://www.goldendb.com/#/docsIndex/docs/instruction_TenantManagement

TDSQL doc: https://cloud.tencent.com/privatecloud/document/123248530626207744/12325495623387545

Zhihu article: https://zhuanlan.zhihu.com/p/445545196

TiDB Follower Read: https://docs.pingcap.com/zh/tidb/stable/follower-read#follower-read

About this article

For questions about attribution, corrections or content rights, please contactadmin@besthub.devand we will review it promptly.

TiDBread-write separationconsistency modelsTDSQLOceanBasefollower readPolarDBdatabase proxyopenGaussGaussDBrouting strategiesGoldenDB

Discussion 0

Questions, practical examples and thoughtful responses.

Open full discussion