Evicting and Removing
In peer-to-peer system design, there are technical tradeoffs between the amount of data synced across peers and the timeliness of access to synced data:
- The greater the amount of data synced across connected peer devices, the more timely offline read access becomes. That is, database resilience in offline scenarios increases when there are more documents being synced across distributed peers.
- The fewer the number of documents replicated, the less the likelihood that peer devices run out of disk space and experience memory leaks, and the performance of the peer-to-peer mesh network that interconnects them degrades.
For considerations on using the Evict and Subscribe methods, see Timing Subscriptions and Evictions.
For advanced concepts related to design tradeoffs in distributed system architecture, see Cloud-Optional Design.
For more information, see Finding and Observing.
In addition, take a balanced approach when using the Subscribe and Evict methods; as in, consider the advantages and drawbacks of each method and use them as appropriate for the specific needs and requirements of your app.
Key considerations for using Subscription and Eviction methods include:
- Use Subscribe to sync more data across connected peers in the mesh, but be mindful of potential increased network usage that may degrade performance.
- Use Evict to remove data stored locally in an effort to manage local storage capacity and improve performance.
Invoking the remove method results in irreversible data loss.
Once a document is removed, it is permanently eliminated throughout the Ditto system and can never be restored; however, as of Ditto version 4.0 release, if a document was previously removed, you can reverse the removal. For more information, see Reversing Removal Operations.
To add a soft-delete pattern, set the isArchived field value to true:
To query to monitor documents that are NOT archived, establish a live query using the Find method enclosed with !isArchived, and then construct your live query callback.
For example, the following code demonstrates looking for documents that are not archived. Once found, the documents output, or log, to your console.
To remove the flag and reactivate the document, set the isArchived field to false: