Has anyone looked into running collab with a nosql database (for example Firebase) without server side code ?
Is this feasible ? as far as I can tell it should be possible, as the authority is basically only doing set/get db transactions which can be fired directly from the client, but are there any other considerations ?
Any thoughts/tips/code appreciated …
I think it’s generally possible (though handling of error states etc would have to happen in the client & clients would have to trust each other).
Your clients would need to make sure that they access a synced global version. To not overwrite each other, it probably makes sense to add a rule in the firebase backend that makes sure that a client update is based on the same version the current firebase (kinda like the _rev in couchdb). It’ll be a hack but probably workable.
p.s.: The client libraries for firebase are amazing - I’ve never written prototypes more easily since they do all the syncing of collections for me. Having said that, at some point I always needed a server to add business logic I couldn’t express in rules.
If your database allows some kind of compare-and-swap or if-not-matches header equivalent (to only increase a counter if the old value was the expected one), you can so this. But as Frederik noted, a lot of the intelligence will have to move to the client, which can not generally be trusted. And things like saving a whole snapshot of the document will have to be done out-of-band, alongside the step data, since the server won’t be able to compute a document from the steps.
Thanks Marijn !
I am trying to understand what you mean by “compare-and-swap or if-not-matches header equivalent (to only increase a counter if the old value was the expected one)” …
Is this for the line
if (version != this.steps.length) return
if yes, can receiveSteps be replaced with a client issued DB transaction that will first get the head revision and only write further steps to the DB if the head is equal to the revision of the last step that was pulled previously ? will this work ?
(I am ok with trusting the clients as this is the nature of serverless apps like Firepad, also I am ok with clients saving snapshots)
Sounds like it would (though I don’t have much experience with this kind of db)
Here’s a working demo of collab with firebase and no server side:
you can open it in two windows and see the collab in action.
Still work in progress so may be buggy but seems to be working fine. This is using an anonymous access db path in my personal firebase. If it get’s abused I’ll remove it.
This is really cool, we can collab without server side code. Prosemirror is fantastic
I’ve updated the code to minimize database space, especially in the case of only one user typing. Steps will be merged on the database and as long as no other client is reading them will be added to a single version.
I started a github project for this here and will post updates there (next challenge is snapshots).