I have a mobile application that syncs documents with couchbase server using sync gateway. When the mobile client pushes a document to the server that requires a task to be run, the sync function adds this document to the “daemon” channel. On the server, I have a script that listens to the changes feed of this “daemon” channel and executes the tasks. In order to keep track of which tasks were already performed, the program saves the last sequence number to the database. When the server process is restarted, it fetches this sequence number from database and passes this to _changes?since=last_sequence, continuing where it stopped before.
Now my question: Is it a problem, that with this architecture the number of documents inside the “daemon” channel grows indefinitely as I never remove the documents from the channel? Will this cause performance issues in the long run, and would it therefore be better to remove the docs from the channel after a task has finished?
If you do not expect to have the documents (representing the server side tasks) to be synced to another clients over the channel , then it would probably be recommended to remove the documents from the channel once the task is completed.
Having a channel with a large number documents will impact size of channel cache and it could also impact the performance of read queries
Thank you for your quick reply! I’ll then mark the tasks as completed by removing the docs from the channel. I see one problem with this approach, though, which is probably unavoidable: If the server has to update every document in order to mark the associated task as completed, this also means that the contents of these docs have to be transmitted to the client again, even though nothing changed for the client. Do you see any way to avoid this?
My specific use case: Users can send messages to others. The sync function adds such a message to the users’ “private” channel and to the server’s “daemon” channel. My server listens to the “daemon” channel and reacts to the messages by sending push messages via firebase. In order to remove the messages from the “daemon” channel again, the server now updates the messages again --> they are retransmitted to the client. As far as I can see, there is no way to avoid this?
If clients are not listening/pulling from the “daemon” channel and it is exclusively for the web client , then they will not see any updates to documents in that channel.
Of course, if the document is also in the user’s private channel, then yes they will see the updates. You’d probably want that by design so clients view of the document is consistent with the server (in this case “status” flag)
That said, if your access logic defined in sync function is such that documents with “status” of completed are immediately removed from the user’s private channel, then the user will no longer see the update. Clients will get a removed doc notification and in fact, that will trigger an auto purge on client side.