Use channels as filtering replication

I am trying to make a decision either use (static)channels as filter at mobile side or dynamically update user channels using admin proxy API.

consider a case where Super Entity → has many sub entities
and each sub entity → has many child entities

There are many argument made like security aspects of it etc.

If User has access to super entity it means it has access to all sub level entities; but user can choose at what level he/she wants to work; which means User can choose to download or work on few child entities at time or few sub entities.

In order to do that Application must handle aforesaid situation. In order to achieve this, two approaches are advised

superEntity channels are [superEntity-1] where 1 is id (format of channel is [superEntity-{ID}])
child entity channels are [childEntity -1] where is 1 is child entity id (format of channel is [childEntity-{ID}])

  1. Use (static)channels as filter at mobile side, Application logic will determine what channels should be passed into pull request (we are keeping channels as some sort of patterns, it can be built in dynamically based on Id and type)

List channels = new ArrayList();

    channels.add("superEntity-1");
    channels.add("superEntity-2");

    pull.setChannels(channels);

In order to download child entity

List channels = new ArrayList();

    channels.add("childEntity-1");
    channels.add("childEntity-2");

    pull.setChannels(channels);
  1. Dynamically update user channels using admin proxy API.

Mobile will consume a proxy sync gateway admin API and let couchbase server know it’s intention that now user wants to download childEntity-1 and childEntity-2; therefore; Admin proxy API will update user channels; returns OK response to mobile. Now mobile can initiate pull/push request.

Both sounds good idea and doable; however, I need to make sure, it remains less volatile at client and server side and security aspects must be covered.

I would appreciate if you could some good insight on it.

@abhi.chouksey,

I think (1.) is the best method right now giving CBL more control over what data to pull.

But in Couchbase Mobile 2.x up coming release this year you will be able to do delta sync(sync only the changed elements in a JSON doc). That way you might not need to make child and parent docs and store your data that best fits your data model and usage vs what best for replication and data usage.

Thanks @househippo. That’s what i have been wondering why couchbase does not have delta sync. It’s good to know that upcoming that feature will be introduced.