Intro
Venturing into the realm of Y.js, I’m impressed by its capabilities, yet grappling with comprehending specific concepts and managing potential conflict states. I’d really appreciate guidance & best practices knowledge.
We are planning to build a PoC Notes App with Y.js, and in this context, an array of technical questions has surfaced.
1. Structure
a. Should every note be it’s own Y.Doc?
I.e. n(Y.doc) = n(notes)
b. Or should there be only one central Y.Doc that has a Y.Array with many Y.Maps which contain each note?
root: Y.Doc = {
notesList: new Y.Array<Y.Map>()
};
1.2 Possible Conflict States
Let’s say there’s Group A that can have access to all notes. But Group B should only have access to a subset notesListB
.
Y.Doc : {
notesListOnlyA: [],
notesListB: [],
}
a. What would be the state of Y.Doc
that Group B receives? Will notesListOnlyA
be empty for them or not even exist ?
b. If a member of Group B syncs their state back to the server, would Y.js assume, since there are no items in notesListA
(as Group B was never allowed access), that the member of Group B deleted all of notesListA
and tries to propagate this state ?
2. Permission/Access Management
As far as I understand, permissions should be checked on the server-side before “commit” of a client’s update to the persistent server-side database provider.
What will happen in a scenario, like above, where the client tries to update properties on the server to a state that the client has no permission to.
Or another example that might make it more clear:
- Member C adds a
note Test
. Member D opens it. - Member D disconnects X
- Member C sets the
note Test
toprivate
(not accessible by D) - Member D makes edits on
note Test
, and various other edits toother notes
- Member D reconnects to the server
What will happens here?
-
Will
note Test
disappear for Member D, including the content they have added tonote Test
? -
When Member D reconnects: will the server (partykit) send a “access denied” for
note Test
property?- Can the rest of the Member D’s data (
other notes
) still be synched or will the whole dataset (all that the user did while offline) be invalid? - Will this result in a feedback loop? E.g. will the client still try to push the update again and again as the server always denies it ?
- Can the rest of the Member D’s data (
3. Data Migration
Y.js is schema-less. However, if a client after a long time comes back online, and the dataset that they try to insert is very different from the current structure, there needs to be some migration strategy in place, right?
What’s the best practice to handle these ? Should a version number be added to each Y.Doc ?
4. General Conflict Resolution Failure Scenarios
Is there a list of common situations where convergence fails, or is not correctness, and hence we need to handle with custom code?