Peer-to-Peer topology

I have some questions regarding possible topologies when implementing P2P snyc with Couchbase Lite 2.5. The documentation describes a scenario with one active and one passive peer.

What is the recommended / best way to implement P2P sync when I have a scenario with N Android devices where each device can manipulate data and these changes should be populated to all other devices? Is there a recommended or required topology, like a star topology with 1 passive and N active peers?

Moreover, if I have a star topology like the above, what happens if the passive peer device makes changes to the database? Will Couchbase Lite then call back the MessageEndpointConnection.send method like it is done one the active peer side? Or is this callback only triggered subsequent to a ReplicationConnection.receive event on the passive peer device? (Which would mean changes made on the passive peer side are not populated to active peers?)

Thank you very much.

What is the recommended / best way to implement P2P sync…

This is a big topic! At this point we’re just providing the building blocks for P2P and not the higher level support for it. We have some customers using P2P and have given them advice, so if you’re a customer you should contact support to bring this up.

I gave a talk about P2P at Couchbase Connect Silicon Valley 2015, with some suggestions on how to set up the peers. I can’t find the video of it right now, but I’m pretty sure it’s still online…

The star topology is the easiest to implement. Changes to the db made on the passive device will be propagated to the active ones.

Found the video:

1 Like

Thank you for the clarification, then I’ll start with that :slight_smile:

And thanks for the video, I’ll definitely have a look at that!

Hello again,
I looked at the video and also started implementing a star topology for replication using the Google Nearby Connections API as communication framework. The problem is that devices often break away from the connections, and when this happens in the middle of the star, aka the passive peer, it makes my life difficult. So, I came to the conclusion that a naïve, fully connected mesh topology could serve me better, as it provides some redundancy (our use case requires the replication of typically less than 5 devices).

Now to my actual question: How should I implement this in view of the Active-Passive replication pattern? My inital thought was to create a pair of active-passive peers for each connection between two devices (meaning that one device can have multiple peers, some active, some passive, like in the picture below)? Would that be the right way to do this?

Thank you

If you’ve got a small number of devices you can definitely do all-to-all replication. The demo app from my talk worked that way.

Generally the device making the connection (the client) is active and the other side passive. It doesn’t really matter who initiates a connection as long as you’re connected, so keep track of which peers have connected to you, and avoid making connections to them unless they close their end. (There are obviously race conditions here if two peers discover each other at the same time, but they shouldn’t cause trouble.)

Thanks for the advice! I’ve got it working now :slight_smile: