Eventing — Server Compatibility

    +

    How Sync Gateway works with Couchbase Server’s Eventing feature

    Related compatibility topics: XDCR | Eventing | Transactions | Collections

    Other related topics: Compatibility Matrix

    This content relates only to ENTERPRISE EDITION

    Introduction

    Couchbase Server provides the backing data store for Sync Gateway.

    See: Compatibility Matrix for version compatibility information.

    Couchbase Server’s Couchbase Eventing Service feature provides a framework to operate on changes to data in real time.

    Here we provide details on how Couchbase Eventing Service relates to data changes in the Couchbase Mobile ecosystem.

    Using Eventing

    You can use Eventing and Sync Gateway connected to the same bucket, when Eventing operates on server buckets in read only mode — see Bucket Bindings for how to do this.

    You should write your Eventing function to be idempotent; to behave correctly when the same mutation is seen more than once. This is necessary because:

    • When a single document update is made directly by Sync Gateway, such as those replicated from Couchbase Lite, it generates a single server mutation that writes both the document body and the metadata.

      But when an update originates outside of Couchbase mobile then multiple mutations are generated. That is because Sync Gateway must update both the document’s body and its _sync metadata (XATTRs).

    • Eventing detects these mutations and invokes its OnUpdate for each; whether it is for the modified body of the document, Sync Gateway metadata, or both. It is here that you need to code the function to apply the same update once only. One way to do this is to use the crc64 function call to identify when an update is to the Sync Gateway metadata only — see: Eventing — crc64() for more on how to do this.

    Eventing prevents inadvertent use of its functions on Sync Gateway read-write buckets. You will see the following warning if you try to do this:
    SyncGateway is enabled on: <bucket-name>, deployment of source bucket mutating handler will cause Intra Bucket Recursion