Database Proxy Cluster Setup Guide for Data Centers

    This guide walks through building a database proxy cluster on your own servers. It covers how to draw the boundary between the database, the proxy layer, and monitoring; how text configuration and runtime state interact during cluster initialization; the four configuration object types; the core configuration steps; read/write splitting rules; monitoring and failover behavior; daily verification and change discipline; common mistakes; and a recommended rollout order that keeps a fallback path to direct connections.

    A data center–grade database proxy is an entry layer that decouples applications from the backend database cluster. Applications connect only to the proxy, which handles connection reuse, account validation, read/write routing, node eviction, and configuration synchronization. It does not replace the database’s own replication and backup. Instead, it consolidates “who reads, who writes, and how traffic shifts when a node becomes unavailable” into a controllable middle layer. The sections below follow a practical order for standing up this kind of proxy cluster on your own servers.

    1. Define the boundary and topology first

    Draw the responsibility lines before touching anything. The database owns data persistence, primary/replica or group replication, transactions, and backups. The proxy owns access, routing, health checks, and configuration distribution. Monitoring owns observation of latency, error rates, and switchover results.

    A typical topology deploys three proxy nodes as peers, exposes a single address in front through a load balancer or DNS round-robin, and points at a backend with at least one write node and several read nodes. Three nodes matter because configuration synchronization then has a majority, so a single proxy does not become a new failure source.

    On the network side, separate the proxy management plane from the business plane: expose the business port only to the application subnet and the management port only to the operations subnet, backed by host firewalls and least-privilege accounts. Address plans, hostnames, weights, and role annotations should be tabulated in advance, so you are not editing configuration from memory after go-live.

    2. Cluster initialization: configuration files vs. runtime state

    Proxy components typically have both a “text configuration” and a “runtime database.” The text configuration suits first-time bootstrapping; the runtime store holds the server list, users, and query rules later pushed through the management interface, and it stays in effect across restarts. Hence a common surprise: the first startup parses the configuration file and generates the runtime store, and subsequent restarts never re-read the file. If you assume editing the file is enough, you get “file changed, behavior unchanged.”

    Recommended initialization order:

    1. Back up the existing configuration and runtime store, and confirm you can roll back.
    2. Write the management-plane parameters: management account, listen address, cluster synchronization account, check interval, and whether servers, users, and rules are persisted to disk.
    3. Declare the cluster members: each proxy’s management address, port, weight, and comment. The weight is a priority reference during configuration synchronization, not a business traffic weight.
    4. Delete the runtime store and restart only when you deliberately want to re-initialize from the file. Deleting it clears all routing, users, and backend lists previously configured through the management plane, so it requires a change ticket and a backup.
    5. Start the service and check the process, ports, and logs, confirming all three nodes can see each other.

    Do not leave the management plane listening on an uncontrolled all-addresses wildcard indefinitely. If a lab phase requires an open listener, tighten the firewall at the same time, change the default password, and switch to subnet binding before production. Keep the cluster synchronization account separate from business accounts, and never put passwords in ticket bodies or chat logs.

    Illustrative management parameters should express what is needed rather than copying one implementation’s proprietary field names:

    • Management credentials and cluster synchronization credentials kept separate
    • Management interface listen address and port stated explicitly
    • Cluster check interval shorter than the failure-detection window, but not so dense that it saturates management connections
    • Persistence switches for servers, users, and rules turned on
    • Synchronize only once differences cross a threshold, to avoid flapping configurations overwriting each other

    3. Architecture layers: four object types

    Think of the configuration as four object types so later changes do not get tangled together.

    Backend servers: address, port, host group, weight, max connections, and status. The host group is the key to routing — for example, a write group and a read group kept apart. Weight influences traffic distribution within a group; status drives up, down, soft-down, and maintenance.

    Users: the account the application uses, its default host group, whether crossing groups inside a transaction is allowed, and max connections. The default host group decides where traffic lands when no special rule matches, and it normally points at the write group so unknown statements are not misrouted to read-only nodes.

    Query rules: split traffic to a designated host group by user, schema name, statement pattern, or annotation. Rules need ordering, explainable comments, and an explicit hit flag; prohibit shipping broad regular expressions that cannot be reviewed.

    The proxy nodes themselves: the cluster member list. Member changes are control-plane changes and should be scheduled in a separate window from business routing changes.

    Configuration generally has several layers: the current running configuration in memory, the persisted configuration on disk, and the pending differences to be synchronized between nodes. The correct habit is “change the running configuration, verify, then persist, then watch synchronization.” Memory-only changes are lost on restart; file-only changes may never be read again.

    4. Core configuration steps

    1. Establish a host group convention. For example, fixed numbers for the write group and the read group, used identically across all documentation and monitoring dashboards, so nobody relies on inconsistent verbal names.
    2. Enter the backend nodes. Give the write node a high weight and distribute read node weights by capacity; mark nodes that should not take traffic yet as offline rather than adding them to the default group and fixing it afterward.
    3. Create the application user, restrict its default target to the write group, and set a connection limit so a misconfigured application connection pool cannot exhaust the backend.
    4. Grant only the necessary monitoring account privileges: the proxy must be able to run health checks and query replication status, but should not get write access to business schemas. Create the monitoring account separately.
    5. Persist the changes, then verify on the remaining proxy nodes that servers, users, and rules match. On any mismatch, stop the rollout and check the synchronization account, network, and management port connectivity.
    6. Run a connectivity, simple read/write, and wrong-password test from a non-production client before shifting traffic.

    Estimate connections as “number of application instances × connection pool per instance × number of proxy nodes,” and leave headroom against the database’s max connections. The proxy reuses backend connections, but the reuse rate depends on transaction length and session state, so do not assume the theoretical ceiling is always reached.

    5. Read/write splitting

    The principle is: safe by default, explicit by exception. Unknown statements, transactions, statements using user variables, and statements that depend on session state go to the write node; clearly identifiable read-only queries go to the read group.

    Usually suitable for the read group: reporting, listing, and search-style statements, provided the business tolerates replication lag. Not suitable: queries that must read what was just written, reads inside a transaction, reads that depend on locks, and administrative statements. If the business is latency-sensitive, pin critical reads to the write group at the application layer instead of letting the proxy guess for all reads.

    Rule design suggestions:

    • Combine rules by “user + statement type” and avoid overly broad matching.
    • State the purpose, owner, and rollback method for every rule.
    • Measure hit counts in staging before opening up production.
    • Set connection limits and timeouts for the read group so slow queries cannot fill read nodes and then drag the proxy down in reverse.
    • When replication lag crosses a threshold, automatically lower that read node’s weight or evict it temporarily instead of continuing to distribute to it.

    Agree the lag policy with the business. For example, alert only when lag exceeds a few seconds, and evict only above a larger threshold. Too small a threshold causes frequent eviction during network jitter and overloads the write node.

    6. Monitoring and failover

    Monitoring should cover at least four layers.

    • Proxy process and port: whether the node is alive and whether the management plane can synchronize.
    • Backend health: whether connections succeed, whether the replication role changed, lag, and read-only state.
    • Traffic quality: query volume, error count, connection occupancy, and rule hits per host group.
    • Business side: whether error rates and the read/write ratio of key endpoints shift abruptly.

    Failure handling should not rely on manual table edits. When a read node fails, the proxy should remove it from the read group and keep traffic on the remaining healthy read nodes; if the whole read group is unavailable, the policy must state in advance whether to fail the request or temporarily fall back to the write node. Falling back preserves availability but can saturate the write node, so a connection limit is mandatory. When the write node fails, the proxy must not “elect” a new primary on its own unless the backend cluster already has an explicit automatic leader election and the proxy can reliably identify the new write node. The safer approach: the database layer completes the switchover and publishes a new write entry point, the proxy updates the write group target, and the application connection string stays unchanged.

    Run drills regularly rather than only documenting them. At minimum: stop one read node, induce replication lag, stop one proxy, and confirm the application needs no connection-string change after a write-node switchover. Record detection time, eviction time, traffic recovery time, and the blast radius for each drill.

    Monitor configuration synchronization itself. A node that has been lagging for a long time may still be serving with old routing. Proxies with divergent configuration behind a load balancer are among the hardest failures to diagnose. On detecting a fork, remove the node from the load balancer first, then repair synchronization.

    7. Daily verification and change discipline

    Use the management interface for daily checks instead of only reading text files. A fixed checklist:

    • Are all cluster members present, and is synchronization lagging?
    • Does the write group point at exactly the currently writable node?
    • Do read group weights match actual capacity?
    • Have offline or maintenance nodes been mistakenly added back into rotation?
    • Do user default host groups still point at the write group?
    • Has a new rule been inserted ahead of others and caused collateral misrouting?
    • Do the running and persisted configurations agree?

    Change discipline: change one object type at a time; change a standby node or a proxy carrying no traffic first; verify, then persist; after persisting, watch the other nodes converge; keep rollback statements ready. Never delete the runtime store to “start over” during business peak hours.

    8. Common mistakes

    • Treating the proxy as the database’s high availability itself: with no leader election process, the primary goes down and someone only edits an address in the proxy, so applications keep writing to the old node or fail to write.
    • Exposing the management port to the public internet or the entire internal network while still using the initial password.
    • Rules so broad that reads inside a transaction go to a read-only node, and just-written data cannot be read back.
    • Editing only the configuration file and ignoring the runtime store, so a restart “doesn’t take effect” — or the reverse, deleting the store and losing production rules.
    • A read-node lag eviction threshold set too low, so all read traffic lands on the write node during jitter.
    • Three proxies with divergent configuration while the load balancer keeps distributing evenly, showing up as intermittent read/write anomalies.

    First, in an isolated environment, bring up three nodes, confirm user connectivity, verify read-only rule hits, and drill a single read-node failure. Then onboard one non-core schema at a low weight. Observe connections, latency, and error rates for one full business cycle. Finally, bring the production write node in, and keep a plan for quickly shifting traffic back to direct connections. The direct-connection fallback does not negate the proxy; it guarantees the business still has a way out when the entry layer misbehaves.

    The value of a data center proxy lies in stable access, explainable routing, and failure handling you can rehearse. Understand the relationship between configuration files and runtime state at initialization, write the write-group/read-group boundary into rules and monitoring, hand switchover to an explicit database high-availability process, and let the proxy follow the new write entry point. Only then will the whole architecture behave as expected during a failure, rather than revealing on the night of a change that the configuration never actually took effect.