Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How would you persist the data in SQL Server? #80

Open
vdurante opened this issue Jan 11, 2024 · 3 comments
Open

How would you persist the data in SQL Server? #80

vdurante opened this issue Jan 11, 2024 · 3 comments

Comments

@vdurante
Copy link
Contributor

Just to get an idea, how should I approach the persisting of the document?

Right now, I am using Redis, which acts like a cache and persists the state in binary format for 5mins or so.

How should I approach persisting the data in a readable/searchable format in SQL Server?

@SebastianStehle
Copy link
Collaborator

This is tricky. The actual state is a binary representation, e.g. see our Mongo implementation: https://github.com/y-crdt/ydotnet/blob/main/YDotNet.Server.MongoDB/DocumentEntity.cs

It is not readable and searchable. if you want that, you need another field and convert the document to JSON whenever you write it. There are a few methods for it: https://github.com/y-crdt/ydotnet/blob/main/YDotNet.Extensions/YDotNetExtensions.cs

If you have a single server I would keep the document in memory and evict it when it is not used anymore. This is what we do in the server project: https://github.com/y-crdt/ydotnet/blob/main/YDotNet.Server/Internal/DocumentCache.cs

If you have a workload with relatively few interactions (not a text editor), you can just load and store it for each request. Perhaps with optimistic concurrency and a few retries.

@vdurante
Copy link
Contributor Author

vdurante commented Jan 11, 2024

@SebastianStehle any reason why both MongoDB and Redis have an expiration date then? If they are the final persistence layers, than shouldn't they be persisted forever? Or do you expect the client to save it somewhere else?

Also, reading MongoDB implementation it seems like you are not really deleting the expired entities? Is the expiration stored there only as an example then?

@SebastianStehle
Copy link
Collaborator

MongoDB is doing the deletion for you (https://github.com/y-crdt/ydotnet/blob/main/YDotNet.Server.MongoDB/MongoDocumentStorage.cs#L30).

I have a use case, where the data is not stored forever, so I added it basically for myself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants