XDCR — Server Compatibility

    +

    How Sync Gateway works with Couchbase Server’s Cross Data Center Replication (XDCR).
    Sync Gateway is specifically designed for mobile synchronization, but there are use-cases where it can usefully be used alongside XDCR to provide a comprehensive solution.

    Related compatibility topics: XDCR | Eventing | Transactions | Collections

    Other related topics: Compatibility Matrix

    Introduction

    Couchbase Server provides the backing data store for Sync Gateway.

    See: Compatibility Matrix for version compatibility information.

    Both Couchbase mobile and Couchbase Server Cross Data Center Replication (XDCR) provide for efficient and secure replication of data, albeit using different replication technologies.

    Here we provide details on how Couchbase Server Cross Data Center Replication (XDCR) feature relates to the Couchbase mobile ecosystem.

    Inter Sync Gateway Replication

    If you need to sync mobile clusters, you should use Inter-Sync Gateway replication — see: Inter Sync Gateway Sync - Overview. It was designed to keep mobile clusters in different data centers in sync. The ideal use-case being the need to replicate edge clusters containing active Sync Gateway nodes between geographically separate cloud-based Sync Gateway deployments. A typical architecture for this use case is shown in Figure 1.

    Inter-Sync Gateway replication provides bi-directional read/write replications that ensure:

    • Cluster specific security is observed; by invoking the appropriate Sync Function.

    • The integrity of security history is maintained. Historical access rules are held and maintained in the Sync Gateway metadata. This history is necessary to consistently handle the revocation of access grants.

    • A consistent Revision Id is used across all clusters, allowing clients to identify a revision regardless of the cluster it is on.

    • Cluster-specific _sync documents are not replicated to other mobile clusters

    icr active mobile sync
    Figure 1. Active-to-active mobile synchronization

    Cross Data Center Replication (XDCR)

    Like inter-Sync Gateway Replication, Couchbase Server’s Cross Data Center Replication (XDCR) can be used to replicate between Couchbase Mobile clusters. XDCR replicates all of Sync Gateway’s metadata (_sync xattr) along with associated documents.

    Your default preference for the replication of Couchbase Mobile changes should always be to use inter-Sync Gateway replication.

    XDCR can be useful though in use-cases where the entire dataset from a source bucket is replicated to a target bucket. This could include categories such as active standby, disaster recovery, data migration and lift-and-shift cases in hybrid cloud.

    In all these categories you should run XDCR in unidirectional mode, deploying Sync Gateway only at one end of the XDCR-replicated bucket (source, or target) — see: Example 1.

    Example 1. XDCR Replication

    In this example XDCR deployment:

    • XDCR is run unidirectionally. It pushes data from the primary data center to the secondary data centers, where it is pulled by Sync Gateway for downstream clients.

    • Sync Gateway, although deployed at both ends of the XDCR replication, crucially is in read-only mode at the target end.

    xdcr data replication to read only
    Figure 2. XDCR Replication

    Disaster Recovery Scenario

    In a Disaster Recovery scenario XDCR serves an important role in setting-up target mobile clusters.

    Here XDCR supports Disaster Recovery and Data Migration. Even though Sync Gateway is the operational replicator of choice for mobile data, it is only ever deployed at one end of the unidirectional XDCR replication.

    Clusters in Same Region

    This model caters for situations where the Active and Disaster Recovery clusters are in the same region or data center — see: Figure 3. It includes an optional optimization step, which will ensure that there is no downtime during the activation stage.

    Set Up

    To set up and maintain a disaster recovery cluster:

    1. [Optional step — for optimization] Connect Sync Gateway to the Disaster Recovery cluster just long enough to create indexes. Having everything reindexed lowers switching costs.
      If you skip this test, you will incur latency when Sync Gateway is switched to the Disaster Recovery cluster and Sync Gateway rebuilds its indexes.

    2. Connect Sync Gateway to your Primary cluster.

    3. Initiate the unidirectional XDCR from the Primary cluster to the Disaster Recovery cluster.

    sgw xdcr dr same regn setup
    Figure 3. DR Cluster Setup (Clusters in Same Regions)
    Activation

    When you are ready to switch to Disaster Recovery operations:

    1. Stop the replication (XDCR) from the Primary cluster to Disaster Recovery cluster.

    2. When XDCR is stopped: Switch the Load Balancer to point to the Sync Gateway on the Disaster Recovery cluster. This maintains the deployment of Sync Gateway at only one end of the XDCR replication.

    3. Promote the Disaster Recovery cluster to Primary and the old Primary to Disaster Recovery.

    4. Flush all replicated buckets in the Primary cluster; as a precaution against any spurious writes coming into the Primary cluster that had not been replicated when XDCR was stopped.

    5. Reverse the XDCR to replicate from the newly promoted Primary to the old Primary to set up a new Backup.

    sgw xdcr dr same regn in recovery
    Figure 4. DR Cluster In-recovery (Clusters in Same Regions)

    Clusters in Different Regions

    This model caters for situations where the Active and Disaster Recovery clusters are in different regions or data centers. Although the model has a separate Sync Gateway cluster attached to the Disaster Recovery cluster, it maintains the deployment of Sync Gateway at only one end of the XDCR replication. The optional optimization step will ensure that there is no downtime during the activation stage.

    Set Up

    To set up and maintain a disaster recovery cluster - see: Figure 5:

    1. [Optional step — for optimization] Turn on Sync Gateway in the Disaster Recovery cluster just long enough to create indexes. Having everything re-indexed lowers switching costs.
      If you skip this test, you will incur latency when Sync Gateway is switched to the Disaster Recovery cluster and Sync Gateway rebuilds its indexes.

    2. [Critical step] Turn off all the Sync Gateways in the Disaster Recovery cluster.

    3. Initiate the unidirectional XDCR from the Primary cluster to the Disaster Recovery cluster.

    sgw xdcr dr diff regn setup
    Figure 5. DR Cluster Setup (Clusters in Different Regions)
    Activation

    When you are ready to switch to Disaster Recovery operations — see: Figure 6:

    1. Stop Sync Gateway on the Primary cluster

    2. Stop the replication (XDCR) from the Primary cluster to the Disaster Recovery cluster.

    3. Ensure that any and all Load Balancer(s) are updated to direct all traffic to the new Sync Gateway cluster(s).

    4. Turn on the Sync Gateway cluster(s) in the Disaster Recovery cluster.

    5. Promote the Disaster Recovery cluster to be the new Primary cluster, and make the old Primary cluster the new Disaster Recovery cluster

    6. Flush all replicated buckets in the Primary cluster; as a precaution against any spurious writes coming into the Primary cluster that had not been replicated when XDCR was stopped.

    7. Reverse the original XDCR to replicate from the newly promoted Primary to the old Primary, to set up a new Backup.

    sgw xdcr dr diff regn in recovery
    Figure 6. DR In-Recovery (clusters in different regions)