TiDB Cross-Data-Center High Availability Using Binlog Bidirectional Replication
This article summarizes the design, working principle, deployment steps, testing results, and future outlook of a TiDB cross-data-center high‑availability solution based on Binlog bidirectional replication, aiming to ensure rapid failover and continuous service between two data‑center clusters.
Background: To improve disaster recovery, the core business requires cross‑data‑center deployment so that when data center A fails, services can quickly switch to data center B, involving multiple TiDB clusters.
Several high‑availability schemes were evaluated; schemes 1 and 2 were too costly, scheme 3 lacked practical value, and scheme 4 was still in pilot testing. The chosen interim solution is scheme 5: Binlog bidirectional replication.
Working principle: Bidirectional synchronization between clusters A and B copies writes from A to B and vice‑versa. To avoid infinite loops, the Drainer adds a _drainer_repl_mark to Binlog events, and the counterpart Drainer filters out marked events.
Note: The prerequisite for bidirectional sync is that writes to both clusters must not conflict, i.e., the same primary key with unique index should not be modified simultaneously.
Cluster architecture:
Deployment steps:
5.1 Deploy bidirectional replication
A‑cluster: (1) Deploy Pump, (2) Enable Binlog, (3) Export full data and import into B, (4) Configure Drainer for incremental replication.
B‑cluster: (1) Deploy Pump, (2) Enable Binlog, (3) Configure Drainer for reverse replication.
5.2 Test bidirectional replication
Various scenarios were tested and the results met business requirements.
Outlook: The Binlog‑based solution is stable but has limitations in concurrency and HA; it is considered an interim approach. The future direction is to adopt TiCDC bidirectional replication, which addresses Binlog shortcomings and is expected to reach GA in 2022.
Author bio and contact information are provided at the end of the article.
HomeTech
HomeTech tech sharing
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.