Sync gateway API REST Vs Couchbase server SDK

Hello everyone!
I’m reading the documentation about sync gateway and couchbase server and I’ve this doubt: Is it better to use Sync Gateway API REST or using Couchbase server SDK to save the documents to the DB and guarantee a fast synchronisation to the mobile devices?
Is there any “operative” difference between these two methods of saving documents?

I’ll make an example:
I’ve a document coming from my web server and I want it to be synchronised through all my mobile devices. I’ve got SG and CBL to synchronise my devices and then Couchbase server to store all the data.
Is it better to make an API CALL directly to SG and create the document or save the document to Couchbase server through an SDK and then wait until SG will synchronise the document to the mobile devices?

I cannot really understand the difference between these two methods of saving the documents, can someone help me?

Thank you!

Hi @LaPomoni ,

The ideal situation would be to make your document writes through Sync Gateway to allow them to be syncronised to mobile devices as soon as possible.

By writing through Sync Gateway, you ensure that the required mobile metadata (i.e. the channel/access grants determined by your sync function) is immediately present on the document when you create it.

You can write documents through and SDK to Couchbase Server and have them syncronise to mobile devices, but it does require additional processing by Sync Gateway first to create this mobile metadata and write it back to Couchbase Server, before sending it to mobile devices.

This process is called document import, and is unlikely to have any perceivable latency, but nonetheless is extra processing you wouldn’t have to do if writing directly through Sync Gateway.

Hope that clears things up!

1 Like

ok @bbrks, thank you very much!