Greetings, Yjs team. Apologies for this noob question. I’m currently using slate. I do persist data in Dynamodb as follows:
Post {
createdAt: TimeStamp
creatorId: ID
title: String
content: JSON String of slate state
}
User {
Id: ID
posts : [Post]
}
I’m not sure how to go from this backend to a Yjs compatible backend.
Do I need to remove the JSON representation of the content and replace it with Yjs data model? How does Yjs db storage model look like?
I learned from another post that Yjs stores only updates. Does that mean that I should create a separate table for the updates, create a relationship between Post and Updates and populate the Post.content field with the last snapshot?
I am particularly confused about how Yjs plays out with an existing backend, can anyone please shed some light on that?
I propose that you start experimenting with Yjs updates. If you have an existing application, you can store the Yjs document alongside the “content” field:
Post {
createdAt: TimeStamp
creatorId: ID
title: String
content: JSON String of slate state
ydoc: String // ideally you store data in a binary field
}
The ydoc field is simply a binary blob:
const documentState = Y.encodeStateAsUpdate(ydoc) // is a Uint8Array
There is a lot of room for optimizations. SQL databases are not well suited for storing incremental document updates. So you could use a combination of Redis and SQL database to store incremental updates instead of the whole binary blob.