Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Collaborative Editing and Scaling Web Based Editor

Collaborative Editing and Scaling Web Based Editor

Tech talk on how to create collaborative editors and scale them to millions of users.

Avatar for Abhishek Gahlot

Abhishek Gahlot

October 03, 2017

More Decks by Abhishek Gahlot

Other Decks in Technology

Transcript

  1. About Me • Same Guy who spoke in the Morning

    • Currently Software Engineer at HackerRank • Worked on Collaborative Editing • Email : [email protected]
  2. Collaboration Use Cases • Online Interviews ( HackerRank CodePair )

    • Expert Sessions • Document Editing • Feedbacks • Online Learning
  3. Eventual Consistency Convergence • Every edit on different clients should

    converge • Balancing servers in order to maintain sticky sessions • Avoid conflicts or divergence
  4. Operational Transform Let T be Transform function such that T(x,

    y) = (x’, y’) x -> insert(1, ‘a’), delete(3) y -> delete(2) Transform function makes sure document converges
  5. Operational Transform Properties • Easy to apply operation • Difficult

    to compute transformation • Too complex and Many corner cases
  6. CRDT Properties 1 + 2 = 2 + 1 (Commutative)

    1 + (2+3) = (1+2) + 3 (Associative) 1 + 1 = 2 ( Not Idempotent )
  7. CRDT Properties A U B = B U A (Commutative)

    A U (B U C) = (A U B) U C (Associative) A U A= A ( Idempotent )
  8. CRDT Types • CmRDT ( Not Idempotent ) • CvRDT

    ( Associative, Commutative, Idempotent )
  9. Web Based Editor • Ace Editor, CodeMirror, Monaco, Draftsjs •

    Extracting tokens ( Read, Update, Delete, Insert ) • Applying Tokens
  10. Other Client Side Requirements • Unique Identifier for Editor or

    Webpage • Local Storage • Collaborative Algorithm Library
  11. Sticky Sessions • Request ending on same server and same

    process • Unique document Identifier • Ability to support failure or Node shutdown
  12. Maintain Sticky Sessions • Use HAProxy ( Default websocket support

    ) • Redirects requests depending on Algorithm used • Algorithms like : IP, Session, URL fragment based
  13. Multiple Servers • HAProxy acts a load balancer • Algorithms

    by HAProxy helps in Node Failure • High Availability
  14. Multiple Processes • HAProxy redirects to master process of NodeJS

    • Customised node module handles id with master process • Master Process redirect websocket connection to child process
  15. Maintaining Connections • Make sure upgrade request is done by

    server • Use proper unique ID for document for Web Socket
  16. Memory Issues • Garbage Collection of Node.JS • Huge JSON

    and Fast manipulation • Increase Heap Size of Node.JS • Atomic Updates