Search code examples
persistencereplicationpersistpouchdbfault-tolerance

How can I implement persistent/fault-tolerant replication using PouchDB?


PouchDB's replicate() functions are not fault-tolerant and will stop replicating if you loose your internet connection or encounter some network disruptions. This is quite frustrating when you need your app to replicate data whenever an internet connection is present.

Sure, you can implement your own retry algorithm, but this requires a descent amount of work. Is there a plugin that we can use?


Solution

  • I've just released pouchdb-persist, a plugin for persistent replication. With this plugin, you can just do

    var db = new PouchDB('todos');
    
    // Instead of db.replicate()
    var persist = db.persist({ url: 'http://localhost:5984/todos' });
    

    You can also listen for the connect and disconnect events.