What is the general architecture for working with an existing backend?

Hello, everyone! This library and community are amazing. I am very new to Y.Doc and CRDTs.

We implemented a collaborative editor with Y.js and Tiptap as an additional feature for our SaaS product. Since we already had a Ruby on Rails backend, we chose the following design:

  • Use WebSocket in Ruby on Rails with ActionCable (we don’t use y-actioncable for certain reasons).
  • Send the encoded Y.Doc state and ProseMirror JSON to the backend and persist it in a MySQL database.

However, I’ve realized that it might be very difficult to create or update the editor content on the backend because it seems challenging to replicate the Y.Doc state exactly as on the client-side.
We need to create or update the data on the backend in the following cases, for example:

  • Creating sample data for onboarding.
  • Importing editor content from an existing source (like Markdown).
  • Inserting additional data into an editor.

I believe the above might be common cases.
How would you generally solve these problems?

Hi, welcome.

Modifying state on the backend shouldn’t be hard at all. The server is just another client in the peer-to-peer replication strategy of YJS. You just fetch the binary updates from your database and apply them to a Doc on the server-side. Then you can interact with that Doc just like on the front-end.

Hi, welcome.
Modifying state on the backend shouldn’t be hard at all. The server is just another client in the peer-to-peer replication strategy of YJS. You just fetch the binary updates from your database and apply them to a Doc on the server-side. Then you can interact with that Doc just like on the front-end.

Hi Raine,

Thank you for your response! I must admit, I don’t fully understand Y.Doc yet.

I may have misunderstood, but I was under the impression that to do the exact editing actions as on the frontend on the backend, I would need to:

  • Use Tiptap on the backend to achieve identical document modifications.
  • Use the exact same encode/decode strategy.
    This process seems straightforward for a Node.js backend but presents challenges with other programming languages.

Is it not necessary to use Tiptap for backend modifications as another client? Can I just modify the state using yrb or something similar and persist it to the database in the same way?
I tried to modify XMLFragment on backend, however, it seems not to contain prosemirror’s Mark for example.

I’m not really familiar with TipTap, but it seems that you could just interact with the underlying data, the Y.Doc, on the backend, without the TipTap editor. YJS shared types have a full range of synchronous CRUD operations that operate directly on the Y.Doc. That’s what TipTap and ProseMirror are doing under the hood.

I think this question is better suited for the TipTap discord or issues page since it is specific to their library.

1 Like

Thank you, raine!

I think this question is better suited for the TipTap discord or issues page since it is specific to their library.

I’ll talk to the Tiptap community about it.