Replication by one user from multiple client devices to the server

#1

I have a general use case question I need some help with:

If a user has two mobiles devices that uses a client app (i.e. a tablet and a phone that uses local data storage couchbase lite). The data on both devices are essentially the same, but stored in different databases and will have different/unique document IDs. The user then uses the client app on the phone to sync data up to a couchbase server.

What happens to the data on the client app on the tablet device once the user decides to sync that client app from that device to the server? Do I need to delete all data on the tablet and then pull data down from the server? or is the replication process smart enough to do that? If I don’t delete the data on the tablet, then there will duplicate data on the server from both the phone and the tablet?

#2

So, you’ve got two client devices that somehow have added the same data to their local databases without using replication? And then they both push to the server?

This will do the right thing if you can ensure that both devices use the same document IDs. In that case, if the data is identical the revision IDs will also match (since the rev IDs are based on SHA-1 digests of the data.) In that case, when the second device pushes, the server will respond that it already has all those revisions, so there will be no duplication.

But you said that the data “will have different/unique document IDs”. In that case the replicator won’t be able to tell that it’s the same data. The server will end up with two copies of everything, with different IDs. (And once the clients pull from the server, they’ll have two copies of everything too.)

I don’t know how the data is being added to the local devices, but is there a way you can ensure that the document IDs are chosen deterministically so that they’ll match on both devices? For instance, you could use a digest of the initial doc contents as the basis for a doc ID, instead of getting a random UUID.

#3

If the document IDs and revision IDs don’t match and there isn’t a deterministic way to ensure the docuement IDs matches, is it a reasonable workaround if I delete the data from the second device and then pull the data from the server to ensure both devices have the same data and can replicate?

#4

Yes, although it would be more efficient to purge the documents on the second device, to avoid leaving tombstones behind.

#5

To clarify,

Deleting the documents on the local device marks them as “deleted”, which will replicate to the server and across other client devices.

Whereas purge permanently deletes them from the database and will prevent the local documents from being replicated unnecessarily to the server and across all other devices?

If documents have already been replicated and exists across devices, then I should Delete them to ensure all documents are deleted as part of replication. If documents have not yet been replicated and only exist in one database, then it should be purged?

#6

That’s correct, although purge isn’t necessarily permanent. If I purge a document, then that doc is updated on a server that I pull from, the replicator will download the new revision (because it thinks it’s never seen that document before.)