## Overview

<!-- markdownlint-disable MD032 -->
> [!NOTE]
> This lab only supports Chrome browser.

This hands-on lab, based on the provided [documentation](https://docs.pingcap.com/tidb/v8.1/two-data-centers-in-one-city-deployment/), will teach you practical skills for deploying a distributed TiDB system spanning two data centers.

In the financial industry, a dual data center architecture is a common deployment model, especially for core business systems. Banks and financial institutions place a high premium on data availability and disaster recovery capabilities. TiDB's DR Auto-Sync solution is specifically designed for such environments, providing robust data protection on dual data center infrastructures while ensuring an RPO (Recovery Point Objective) of 0 and an RTO (Recovery Time Objective) measured in minutes. Specifically, this solution offers the following features:

+ RPO = 0: Ensures no data loss even in the event of a data center failure.
+ Minute-level RTO: Enables service recovery within minutes after a failure.
+ Active-active services: Allows both data centers to simultaneously provide highly available data services.

This lab simulates the deployment of DR Auto-Sync in a dual data center scenario, demonstrating how to achieve data consistency and high availability when one of the data centers is unavailable or experiences network disruptions.

### DR Auto-Sync Solution Introduction

Challenges with Default Deployment

+ By default, all database replicas (3 replicas) form a Raft group where any two replicas can ensure database availability and data persistence. For each data write, as long as it is committed in any two TiKVs within the Raft group, the client will receive a success response. However, if Data Center 1 holds the two latest data replicas and it experiences a complete outage, these two replicas are lost, and the Raft group can not guarantee the latest data is replicated to Data Center 2.

  ![60%](https://lab-static.pingcap.com/quick-demo/demo-303-1-en.png)

DR Auto-Sync Solution

+ This solution introduces the concept of a commit group to the Raft algorithm. For data to be committed, it must not only meet the majority rule but also be present in at least two commit groups. This guarantees that both data centers hold the latest data copies, ensuring data safety.

  ![60%](https://lab-static.pingcap.com/quick-demo/demo-303-2-en.png)

Additionally, this solution includes an extra learner node in DC2, which doesn't participate in voting and is used to restore the TiDB cluster only when DC2 is the sole surviving data center.

High Availability Scenarios with DR Auto-Sync

+ The DR auto-sync solution uses three distinct states to identify TiKV data synchronization modes. The replication mode of the cluster can automatically and adaptively switch between the three statuses.

  ![60%](https://lab-static.pingcap.com/quick-demo/demo-303-3-en.png)

  + Sync Mode: TiDB operates in synchronous replication mode by default. In this mode, at least one replica in the disaster recovery data center synchronizes with the primary data center. The Raft algorithm ensures that each data is replicated to the disaster recovery data center. In this state, the overall failure of any data center can ensure that the TiDB cluster achieves an RPO=0.

  + Async Mode: When a failure occurs in one entire data center, TiDB switches to asynchronous replication mode. In this mode, the data in these two data centers are not fully synchronized. The Raft algorithm degrades to follow only the majority quorum protocol, completing data replication within the surviving data center. Since a failure has already occurred, the TiDB cluster cannot guarantee an RPO=0 if a second failure happens. The cluster can only regain its RPO=0 high availability capability after the initial failure is resolved.

  + Sync-recover Mode: The data center failure has been resolved, and data synchronization between the two data centers is in progress. TiDB switches to synchronous recovery mode. In this mode, these two data centers are not fully synchronized. After data synchronization is completed, TiDB switches back to Sync Mode. Then, the TiDB cluster regains RPO=0 HA capability.

### Tasks

+ Module 1: Set up the TiDB cluster and configure DR Auto-Sync deployment, verifying the correct setup of the high-availability mode.
+ Module 2: Simulate a disaster recovery data center failure or network isolation, observing the cluster's automatic switching and recovery mechanisms.
+ Module 3: Simulate a primary data center failure, verifying the cluster's failover behavior and rapid recovery capabilities.

### Objectives

Through simulating a dual data center scenario, this lab demonstrates how TiDB's DR Auto-Sync solution achieves high availability and strong consistency across data centers. This solution not only resolves potential failures and data loss issues in traditional dual data center architectures but also enhances TiDB's flexibility and disaster recovery capabilities through dynamic synchronization mode switching.

DR Auto-Sync is particularly suitable for core business scenarios in the financial industry requiring high reliability and zero data loss, such as payment systems, clearing systems, and account management systems. This lab offers an intuitive understanding of TiDB's unique advantages and practical capabilities in a dual data center architecture.

> [!TIP]
> Click **Start** to launch the lab environment.
> Once the environment is ready, the resources assigned to your hands-on session will be populated with the actual values, so you can follow the lab guide step-by-step to complete the practice.
