Realtime P2P Database over LAN network

Hi,

I am trying to gather some advice/thoughts on how to implement a realtime database that syncs between iPads in the same LAN network.

After reading through the forums it seems this is very achievable with Couchbase and its Replicators, using Bonjour to handle peer discovery, but I have a couple questions:

There needs to be one iPad that acts as a “server”, correct? Should all the iPads set their push/pull replicators to this “server” iPad?

I’m asking this because from what I understand you setup a Replicator to a single specific URL (which I will get using Bonjour) which in my case is going to be a given device on the network… Should this URL be the one of the “server” iPad?

Can all iPads be setup to replicate with each other? If so, how would you go about setting this up?

Is this the correct way to go about this? Or is there a better approach that I might be missing?

Thanks!

Hi @jeremias

Please go through below links to know how peer to peer works in an Ios App.

Also I have found following project very useful to know tips and tricks. :-

Also following forum discussion can be helpful :slight_smile:

Regards
Pankaj Sharma

That isn’t necessary, and it has scaling problems because you’re bottlenecked by the performance of the node acting as the server. The server also acts as a single point of failure.

The replication protocol is “multi-master”, which means that any node can act as client and/or server. For example you could have each peer replicating with each other peer and it would still work; it’s just that it would use a lot more local and network resources than necessary due to redundant change notifications. The minimal topology is a spanning tree, i.e. a tree that connects all the nodes, but it can help to have some redundant connections (cycles) to improve latency. You can look into the topic of Mesh Networking to find more information (but it’s a deep dive!)

What kind of scale are you thinking of? There’s a big difference between connecting 5 devices and connecting 100.

Hi Jens, thanks for your reply.

We are thinking of about 5-20 devices to start with (it’s very unlikely to have 20 though).

What I’m not too sure about is how to set the URL for the push/pull replicator on each device. From what I saw in the PhotoDrop sample app they use a CBLListener, grab its URL and then send it to the other device, and then use that URL to setup the replicator on the receiving device.

I am not too sure where this CBLListener component fits into the whole scheme of things, or if I should even use this at all for our implementation. I thought the replicator was its own HTTP server, is that incorrect?

No, the replicator is an HTTP client. The listener is the matching server. You’ll need it for P2P.

So we would need a push/pull replicator and a listener for each device? Sorry if the questions are a bit dumb, I’m just trying to validate my approach on this in order to start prototyping

Basically yes. You can get by with just pull or just push (in addition to the listener), as long as the connections are all bidirectional, i.e. A pushes to B and B pushes to A. Of the two, the push replicator is a bit lighter weight because even in continuous mode it doesn’t leave a socket open when it’s idle, unlike the puller.