Delta Sync

    +

    Use Sync Gateway’s delta sync feature for secure, resilient and efficient sync from cloud to edge
    This content introduces Sync Gateway’s delta sync feature; sync only the data that has changed.

    Overview

    Delta Sync provides the ability to replicate only those parts of a Couchbase Mobile document that have changed. This can result in significant savings in bandwidth consumption as well as throughput improvements, especially useful where network bandwidth is constrained.

    Operation

    Delta sync is disabled by default on Sync Gateway databases.

    If delta sync is enabled on a Sync Gateway database (see: Example 1), then Couchbase Lite clients syncing with that database will switch to using delta sync automatically. It is also automatically enabled for peer-to-peer sync between Couchbase Lite clients. However, if delta sync is disabled on Sync Gateway then Couchbase Lie clients will operate in normal mode.

    You should note that delta sync does not apply to attachment contents and that it is disabled for Couchbase Lite database replicas.

    Push replications do not use Delta Sync when pushing to a pre-2.8 target.

    Configuration

    You can enable delta-sync on a per-database basic in your Sync Gateway configuration file using the this_db.delta_sync properties — as shown in Example 1:

    Example 1. Sample of Database with Delta Sync
    // ... other configuration properties as appropriate
    {
      "logging": {
        "console": {
          "log_keys": ["*"]
        }
      },
      "databases": {
        "db": {
          "server": "http://localhost:8091",
          "bucket": "default",
          "users": { "GUEST": { "disabled": false, "admin_channels": ["*"] } },
          "allow_conflicts": false,
          "revs_limit": 20,
          "delta_sync": {
            "enabled": true, (1)
            "rev_max_age_seconds": 86400 (2)
          }
          // ... any other configuration properties as appropriate
        }
      }
    }
    1 this_db.delta_sync.enabled — enabled or disables delta sync for this database
    2 this_db.delta_sync.rev_max_age_seconds — allows you to tune the amount of additional Couchbase Server bucket storage used by delta sync — see: Couchbase Server Bucket Storage Needs.

    Couchbase Server Bucket Storage Needs

    Delta sync’s storage of backed up revision bodies in the Couchbase Server bucket means additional Couchbase Server storage is required — see Example 2.

    Calculate required storage using: doc_size * updates_per_day * 86400) / rev_max_age_seconds

    With each delta sync write operation the revision body is backed up in the bucket and retained for rev_max_age_seconds to calculate future revision deltas. So new deltas can only be generated for read requests arriving within the rev_max_age_seconds time window.

    Setting rev_max_age_seconds = 0 will generate deltas opportunistically on pull replications, with no additional storage requirements.

    Example 2. Additional storage calulation

    Using:

    • rev_max_age_seconds = default value

    • average document size = 4 KB

    • writes/day = 100

    Then enabling delta sync would take up an additional 400 KB of storage on Couchbase Server:
    ((4 * 100 * 86400)/86400)