1

I have an app based on FabricJS, storing the resulting drawing in JSON format in a file on a Linux server using a php backend.

I'd like to implement collaboration on the app so that several people can interact with the same drawing like Miro. This bit is easy enough- I'm intending to use websockets to broadcast little updates e.g. 'User 1 has moved object A to coordinates x,y' which are received and update the other clients.

What I'm wanting to know is an efficient way to store those changes in a persistent file in the backend. Currently the drawing is stored on a file on Linux, which is referenced by a database.

Any ideas?

Trivially I could just save the file every time the drawing is updated but that would be inefficient. Ideally I'd update the json on the backend when the updates happen, but can't work out how to just incrementally update a json file.

Wilheim
  • 11
  • 2
  • If you don't want to update the file on the server - then you will have to broadcast each change to all the other clients so that they update their local drawing in the browser. Depending on the number of the clients such a broadcasting could be as inefficient as updating the file on the server. – IVO GELOV Apr 03 '23 at 08:51
  • I want to do *both*- broadcasting atomic changes is how Miro works, for example. But I also want to store it on the server so it can be retrieved by a new participant/backed up etc – Wilheim Apr 04 '23 at 03:23
  • Then I would suggest a solution of 2 parts - maintain a queue where each client will push one change at a time and this change will be also broadcasted to all other online clients. At the background you will have another process that will periodically read (pop) from the queue, apply each change onto the model and save it. Then, any time a new client connects - it can read the current representation of the model plus the queue (so it can apply the pending changes that haven't been picked up yet by the background process). – IVO GELOV Apr 05 '23 at 10:04
  • Maybe this would be interesting to you - https://logux.io/ and https://automerge.org/ – IVO GELOV Apr 07 '23 at 09:10

0 Answers0