Hi, I’ve always asked myself if it was possible to synchronize clients via “serverless” functions / lambdas + a persistent database (I’m thinking hosted Postgres or even Firebase).
This example in the manual - https://github.com/yjs/yjs/blob/master/README.md#example-sync-two-clients-by-computing-the-differences - wouldn’t work, since the server has to keep track of what is the last state of each client.
I was thinking: wouldn’t it work for each client to:
1 - persist each doc update* via a call to a store
lambda, which saves the update in the database
2 - periodically poll a get-updates
lambda, which queries the db for updates. Each client knows the id of the last update received, so the query will just get the updates stored later**
My reasoning is that, since the updates can be applied in every order, the main concern of a client would be getting them all, but not necessarily in a particular order relatively to the document updates. Essentially, the two queries could work independently inside each client. The lambdas would just have to do dumb, sequential updates (store) and ranged queries to a database (get-updates).
Could it work? Or am I missing something fundamental?
(*) or every n updates, debouncing them
(**) A cron function could also run periodically on the lambda side, compacting the updates up to a certain id, but that’s an optimization.