Copy & pasting my reply to issue https://github.com/blockstack/blockstack-todos/issues/31#issuecomment-499942217 –
Some thoughts I’ve had regarding difficulties with using gaia’s API for simple CRUD-like operations –
Also pinging @hstove since he has been thinking about this as well (radiks-lite ?).
One of the main problems with apps that require CRUD-like operations (most apps) is how difficult it is to do anything reliably .
The common approach is to maintain a index.json file that could be as simple as an array of uploaded files. Another approach is a single large content.json kind of file that stores everything. Another could be using Radiks, which I think helps here but does not fully eliminate the problem, depending on the app design.
I just tested out graphitedocs, and surprised to see that I can’t even have the same document open in multiple tabs without data loss. That isn’t even an indexing problem, but same underlying issue.
All these approaches can cause race conditions, resulting in an incorrect app data state. Correcting for these race conditions requires complex and expensive conflict resolution code where:
- Every file update & upload must be followed by a download of the same file, followed by state comparison to ensure the changes were written and the state is correct.
- Additional code to perform conflict resolution in the event of invalid state.
- Also, because the app window can closed or connection lost during this process, you’d need to store all current state and pending operations in localStorage before even attempting upload.
Some of these race-condition problems could be solved with something like a webrtc data channel layer. I could have this Notes app open in a couple tabs and on my phone, and the instances could sync state with each other while online. This is relatively complex to implement, and might not make sense to add to blockstack.js. A second layer lib, like radiks-lite, could perhaps do this.
The second layer lib could also implement the localStorage caching for dropped connections or offline apps, and some abstracted or common form of conflict resolution.