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 topics: XDCR | Eventing | Transactions | Collections
Other 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 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
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.
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.
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.
To set up and maintain a disaster recovery cluster:
-
[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. -
Connect Sync Gateway to your Primary cluster.
-
Initiate the unidirectional XDCR from the Primary cluster to the Disaster Recovery cluster.
When you are ready to switch to Disaster Recovery operations:
-
Stop the replication (XDCR) from the Primary cluster to Disaster Recovery cluster.
-
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.
-
Promote the Disaster Recovery cluster to Primary and the old Primary to Disaster Recovery.
-
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.
-
Reverse the XDCR to replicate from the newly promoted Primary to the old Primary to set up a new Backup.
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.
To set up and maintain a disaster recovery cluster - see: Figure 5:
-
[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. -
[Critical step] Turn off all the Sync Gateways in the Disaster Recovery cluster.
-
Initiate the unidirectional XDCR from the Primary cluster to the Disaster Recovery cluster.
When you are ready to switch to Disaster Recovery operations — see: Figure 6:
-
Stop Sync Gateway on the Primary cluster
-
Stop the replication (XDCR) from the Primary cluster to the Disaster Recovery cluster.
-
Ensure that any and all Load Balancer(s) are updated to direct all traffic to the new Sync Gateway cluster(s).
-
Turn on the Sync Gateway cluster(s) in the Disaster Recovery cluster.
-
Promote the Disaster Recovery cluster to be the new Primary cluster, and make the old Primary cluster the new Disaster Recovery cluster
-
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.
-
Reverse the original XDCR to replicate from the newly promoted Primary to the old Primary, to set up a new Backup.