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

Consider using Automerge for syncing object across nodes #19

Open
justvanrossum opened this issue Apr 29, 2022 · 4 comments
Open

Consider using Automerge for syncing object across nodes #19

justvanrossum opened this issue Apr 29, 2022 · 4 comments
Labels
question Further information is requested research Reasearch to be done before deciding a feature is viable

Comments

@justvanrossum
Copy link
Collaborator

https://automerge.org/

Thinking:

  • A single glyph should probably a "document", in automerge terms

Question:

  • There is no Python implementation, would our server need a JS component?
@justvanrossum
Copy link
Collaborator Author

Or https://github.com/yjs/yjs

@justvanrossum
Copy link
Collaborator Author

justvanrossum commented Apr 29, 2022

Or https://github.com/share/sharedb/ Meh.

@justvanrossum
Copy link
Collaborator Author

justvanrossum commented May 1, 2022

CRDT

So, the buzzword here is "Conflict-free replicated data type" (CRDT).

It is a very cool concept and mechanism, and it may be useful for us.

These tools are designed to allow data to diverge: edited by two or more parties, then synced later, say, after one of them comes back online. So it is ideal for apps that allow the user to continue working even if the connection to the server was lost, even for a longer time.

The algorithms behind Automerge and Yjs are designed to never cause merge conflicts: it is always defined what will happen if two parties edit something near each other or even overlapping. I can see how this works for text-like data, but I'm not sure this is what you'd want for outline data: we intuitively know that some edits are incompatible, and there is no way to automatically resolve the situation without accepting one person's work will be (partially) lost.

Perhaps something in-between is possible: automatically merge if there is no conflict at all, and always ask the user to review if there is a conflict.

Automerge is cool in that it considers all objects to be immutable, and each mutation results in a new object. This is supposed to be done in an efficient way, but I'm curious how well it would perform with our kind of data (which is tree-like rather than sequence-like).

I need to read more about how Yjs works. Some say it is faster than Automerge.

Beyond collaboration

The mechanism is useful beyond (remote) collaboration:

  • undo/redo could be implemented using these tools (edit: Yjs has a complete undo solution)
  • working with branches

CRDT and Fontra

Our immediate practical problem is that the official libraries are written in JavaScript (and Rust), and with our current architecture, we need it to work in Python, too. So that's a bit of a show-stopper for immediate experimentation.

The alternative for Fontra is to make something ourselves, which would a huge rabbit hole. But then again, we could limit our requirements. For example:

  • Collaborative editing requires a network connection to a server or to a peer. Maybe we don't strictly need offline-yet-collaborative editing.
  • We could use a locking system like RoboCJK on a per-glyph basis: if one person is edting a glyph, no one else will be permitted to edit it at the same time.

This is much easier to achieve, but still requires us to build a lot of infrastructure.

We could also say: we will initially have a more limited set of requirements, and intend to upgrade to a proper CRDT-based appraoch later. One question will be: how much work will be wasted by this two-step timeline?

More links

@justvanrossum justvanrossum moved this to Todo in Fontra Project May 25, 2022
@justvanrossum justvanrossum moved this from Todo to Research in Fontra Project May 25, 2022
@justvanrossum justvanrossum added the question Further information is requested label Jun 8, 2022
@justvanrossum
Copy link
Collaborator Author

From @davelab6 in #238 (comment):

https://automerge.org/blog/automerge-2/ has impressive numbers, might be relevant

@nedkamburov nedkamburov moved this to 🆕 New in Fontra Project Feb 9, 2023
@justvanrossum justvanrossum moved this from 🆕 New to 📋 Backlog in Fontra Project Apr 12, 2023
@justvanrossum justvanrossum added the research Reasearch to be done before deciding a feature is viable label Jun 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested research Reasearch to be done before deciding a feature is viable
Projects
Status: 📋 Backlog
Development

No branches or pull requests

1 participant