Hi Team,
I know that documents are synced via sync gateway. But we have a peculiar problem and it is a long post (Sorry for that ). I recommend reading it completely and calmly . We currently have an app which works as an offline first solution.
This app is developed using .Net, SQL server at server and client both. SQL server at server and SQL server express edition at local. We use tablets to run this app. These tablets have Windows.
Now the APP always get data from local DB (SQL server Express Edition) and data manipulations (Which can be done by using couch base lite). When the tablet is in online (reachable to server) there is a windows service sync data with server in background.This is done on multiple tablet in a near by area.
If in critical situations if connectivity is not available we have provided an option by which two tablets can sync their data via Bluetooth. One tablet sends data as a file and other receives it, process it and put data in its local DB.
When both tablets comes online conflict resolution is done and data is synced back to server. Right now we are doing it using Bluetooth but we do have plan to use WiFi direct.
Now my question is if we want to achieve this using Couch base lite and Andoid / IOS, how we can do this?
First solution comes to my mind is reading changed documents and sending then over Bluetooth/WiFi direct to other device as a file and then reading it and saving it with same revision number. but the question is whether it will confuse the sync gateway?
If we can have a better solution that I will highly appreciate your effort.
Couchbase Lite is its own database. It doesnât work with external databases. If youâre already using Couchbase Lite, Iâm confused as to how it connects with SQL Server. You must have written your own code to copy data between them?
In general it sounds like youâre trying to reimplement our replicator yourself using SQL Server and Bluetooth. Replication is a hard problem and very difficult to get right, and if youâre not using our technology for it Iâm not sure how we can help you.
To restate this more positively: You can use Couchbase Liteâs replicator in peer-to-peer mode to sync changes between two devices without going through Sync Gateway. This wonât confuse the Gateway; the replication protocol is multi-master, meaning that changes can flow through an arbitrary topology of peers, not just in a traditional client/server star shape.
We are planning to rewrite the app using Couch base Mobile So we will not be using SQL server or any other DB apart from couch base mobile framework. The explanation I wrote is about how does it work right now and how we have implemented it. And we want to move away from it and want to use a system which have built-in sync. So the question is how we will be able to do it using couch base mobile?
[quote=âjens, post:3, topic:12219â]
You can use Couchbase Liteâs replicator in peer-to-peer mode to sync changes between two devices without going through Sync Gateway
[/quote]
If you can provide more information on this, May be some link then it will be help full. We will be using Android OR I-OS now on-wards.
We donât have a turn-key P2P solution yet, but we provide the building blocks to do it.
When you start a replication you give it a URL for the remote database. This is simply an HTTP endpoint that speaks the REST-based replication protocol.
Couchbase Lite has an optional âListenerâ component that runs a simple HTTP server, providing REST API access to your local databases. This is most commonly used to let an embedded web-app access the databases via XMLHTTPRequest, but if you bind the listener to a network interface (not just loopback) other devices can connect to it.
The REST API implemented by the listener includes the API methods used for replication.
Put this together, and if you enable the listener in Couchbase Lite on one device, then run CBL on another device and give the replicator a URL that points to the endpoint being served by the first device, the two peers can replicate (in either or both directions.)
The replication protocol is multi-master, so multiple peers can replicate with each other, and the topology doesnât have to be a star. You can have an arbitrary directed graph, and updates will flow across it.
In practice, the missing pieces you need to implement are mostly about discovery and simplifying the topology.
Discovery means how the peers on the network find each other. To construct the URL to replicate with a peer, you need to know its IP address or hostname (and the database name, which is usually hardcoded.) Peers will tend to come and go dynamically without fixed addresses. Most often youâd use zeroconf discovery (mDNS and DNS-SD), which Apple calls âBonjourâ, for this. Itâs obviously well supported on iOS and macOS, but itâs also in Android under a different brand name, and there are versions available for Linux (Avahi) and for Windows (donât recall the name.)
At a small scale you can just have every peer replicate with every other peer, but the amount of traffic on the LAN increases as O(n^2), so this doesnât scale. With larger numbers of peers you want to prune the connection graph to something more like a spanning tree, which requires some tricky distributed algorithms. Iâve never tried to implement this, but there is a lot of literature about it if you search for âmesh networksâ or âad-hoc networkingâ.
A few customers of ours have built systems like this. Weâd love to have a turn-key system of our own, but we just havenât had the resources to build it yet.
We successfully implemented it using android as suggested by @jens. Thanks sir.
There are some question from my side as always :-
I have read somewhere (May be in Github at the wiki of 2.0) that the Blip protocol you are designing will support Peer to Peer sync using bluetooth. Will it support for all platforms?
Right now web socket is not available in Android. Is it a correct statement. If yes then will it be available in 2.0.
Why there is a big difference in pull replicator performance between Android and Ios?
I have read somewhere (May be in Github at the wiki of 2.0) that the Blip protocol you are designing will support Peer to Peer sync using bluetooth. Will it support for all platforms?
Itâs capable of running over Bluetooth. We have no implementation of that currently.
Right now web socket is not available in Android. Is it a correct statement. If yes then will it be available in 2.0.
I canât speak for Android 1.x, but the replicator in 2.0 uses WebSockets on all platforms.
Why there is a big difference in pull replicator performance between Android and Ios?
Likely due to the overhead of a Java implementation vs. native code.
Hi @pankaj.sharma
quote=âpankaj.sharma, post:7, topic:12219â]
We successfully implemented it using android as suggested by @jens. Thanks sir.
[/quote]
Curious: Which version of CBM did you implement this on (Assuming you were able to locate the Android version of the photoDrop app)? Did you use Android NSD for peer discovery?
I was not able to locate Android photoDrop App. So We used NSD for Peer discovery and made hot spot on one serving device and client on the other. Then we exchanged the URL and its done.