I am developing an single page application that relies on PouchDB for storing state when a user logs in with the app. My application state consists in user data such as email address, first name, etc.
I am new to PouchDB and the concept of storing data in the browser. I am wondering what the best practices are when dealing with issues such as deleting/purging data from PouchDB for a given user...
What are the pros and cons of keeping data/documents in PouchDB/IndexedDB (versus deleting it) when the user signs out or closes and leaves the SPA?
In other words, what would be example use cases of keeping the data and use cases for deleting it upon user log out?
Typical use cases of deleting data once the user logs out might be:
Note: At best you do not need to store data like mentioned above in PouchDB but this is beside the point.
Use cases for keeping data after log out:
This mostly comes down to user experience versus freshness of data.
PouchDB is meant to allow an app to keep data locally and sync it with a backend system. (CouchDB and Couchbase are both currently supported, as examples of backend servers.) It's also designed to allow multiple clients to make changes.
Most databases expect high-availability of a central system. They are designed to resolve conflicts immediately. With PouchDB you expect conflicts that may not be resolved at client write time.
The core idea is that your app will be used with poor or no network connectivity at times. Keeping information locally means your application can continue to work, even in these situations.
The main tradeoffs:
Keep
Delete/Purge
Note PouchDB is a NoSQL database. NoSQL databases can't enforce "ACID" compliance. This means if your app needs data changes to be atomic (transactional), this is the wrong solution.
There are plenty of use cases where eventually consistent data is fine. This can be as simple as having a single client and the backend system "agree" on what's correct. Or it can be a complex system with multiple writers making changes that eventually propagate and get integrated.
There's also security to consider. Will you give the user a way to remove sensitive data in case they're on a shared machine, that sort of thing.
As a final note, you might want to search for 'offline first' as an approach to app development.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With