Skip to content
This repository was archived by the owner on Oct 4, 2024. It is now read-only.
This repository was archived by the owner on Oct 4, 2024. It is now read-only.

OT Question #163

Closed
Closed

Description

@dcworldwide

Hi, could you please explain how OT works within Firepad?

I'm running the user list demo locally. I've noticed the code has an OT implementation. But the code only talks to the Firebase server, which confuses me as i thought OT required a server component?

Activity

  1. mikelehen commented on Mar 6, 2015

    @mikelehen
    Collaborator

    Good question. I've been meaning to write up a doc on this at some point, but haven't gotten around to it. I'm not going to go into too much detail unless you have specific questions, but the basics are:

    1. Firepad uses OT, but it's implemented completely client-side. Firebase doesn't need to be OT-aware.
    2. When you make an edit, the client turns that into an OT operation and tries to append it to a log of operations stored in Firebase, using a transaction.
    3. If there's a conflict (i.e. some other client appended something new to the log before our transaction completed), the client will use OT to transform its operation against the newly added operation, and then it will attempt again to append the (now) transformed operation to the log. This can potentially happen multiple times if there's contention on the log.

    Number 3 is where firepad differs from most implementations, which do rely on the server doing the transform, as you say.

    I'm going to close this, but feel free to reply if you have further questions.

  2. dcworldwide commented on Mar 10, 2015

    @dcworldwide
    Author

    Great explanation thanks. Quite a clever design actually. I found it quite difficult to make sense of the code given the size of the code base. I'll have a go at reverse engineering your work so that i can better understand it.

  3. mikelehen commented on Mar 10, 2015

    @mikelehen
    Collaborator

    Glad it was helpful. Yeah, sorry the code isn't more readable. It could use some cleanup and better documentation for sure.

    If it's helpful, the operations and their transforms are defined in text-operation.js (and text-op.js). The higher-level OT mechanism (deciding when/how operations are transformed against each other and resent) lives in editor-client.js and especially its base class client.js. And the interaction with firebase (e.g. using transactions to append to the revision history log) lives in firebase-adapter.js.

    If you have more specific questions, feel free to ping me (michael at firebase.com). Good luck.

  4. vincentwoo commented on Mar 10, 2015

    @vincentwoo
    Collaborator

    @mikelehen as an aside, I'd really love the aforementioned doc. I've had to pass around a ham-handed description of the Firepad OT format to certain users who are interested in their per-edit data and having a resource to point them at would be pretty useful.

  5. mikelehen commented on Mar 11, 2015

    @mikelehen
    Collaborator

    @vincentwoo Cool, I'll keep that in mind.

  6. cben commented on Mar 19, 2015

    @cben
    Contributor

    ... This can potentially happen multiple times if there's contention on the log.

    What happens if there is very high contention (many edits per round-trip time)?
    At least one client always succeeds, so progress is being made, right?
    I suppose users will simply see rarer bigger incoming changes.
    But if one client has much higher latency (California vs satellite over Australia...), can it get consistently starved?

    And would server-side OT avoid that?
    (I don't expect such high usage, just curious to understand the tradeoffs of client-side OT...)

  7. mikelehen commented on Mar 19, 2015

    @mikelehen
    Collaborator

    Yep, it's exactly as you say (nice work :-)).

    Progress will always be made (/somebody/ is able to append to the log), but there is the potential for starvation if somebody has very high latency. In practice, I've never heard of this actually happening though. It's rare to have more than a few collaborators at a time, and even if you do, people's typing tends to be very "bursty" (with long pauses of multiple seconds while they think about what to type next), and this gives "starved" clients a chance to catch up.

    It's worth noting that a client will automatically merge all of its outstanding changes together each time it tries to append to the log, so even if a client gets starved for a while, it only needs to successfully write to the log once to catch up completely.

  8. mohdsanadzakirizvi commented on Apr 25, 2018

    @mohdsanadzakirizvi

    Hey @mikelehen

    I'm a student and I need to understand this for a project. I'd like to take up the challenge of documenting "how everything works?"

  9. mikelehen commented on Apr 25, 2018

    @mikelehen
    Collaborator

    Cool, good luck! If you have specific questions I can try to answer them. 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions