You often want to build an app as quickly as possible. To get some kind of MVP in the hands of users, giving them value and something for you to incrementally improve. Most features can come later, but if you ever intend to offer a shared editing experience of any kind, you really need to think about it up front.
At Threads Styling they were faced with such a prospect when planning their Social Story builder. Having worked with CMSs in the past, they knew the pain of managing document locks with all their edge cases. They also knew that eventually the use case will arise to concurrently edit the document, and if you haven’t planned for it, it is a monumental task.
By treating the document as a stream of JSON patch changes from the very beginning, they were able to offer real-time collaborative editing with conflict resolution smoothly handled by an Operational Transformation algorithm. In this talk, Jason will build a simple, but working example of a shared document using our open source library.
3. Who am I, and what
am I doing here?
https://giphy.com
4. Jason Green
Principal Developer at Threads Styling
@aziraphael @threads_eng
Geeky Twitter handle from 10 years
ago which is no excuse cause
I was still 25 years old.
Revolutionary chat commerce
company changing the world
of luxury shopping.
11. What did we want
• To keep it simple (as Agile as possible)
• To own our data and control it
• To keep it flexible
• To understand how it works
• To keep data eventually consistent across multiple users
• To support arbitrary JSON data structures
12. So what were the options?
• Conflict-free replicated data type (CRDTs) - redis, riak
• Differential Synchronisation - git, svn
• Operational Transformation - google docs
reference: https://irisate.com/collaborative-editing-solutions-round-up
13. Operational
Transformations
Operational Transformation (OT) is an algorithm/
technique for the transformation of operations
such that they can be applied to documents
whose states have diverged, bringing them both
back to the same state.
reference: https://medium.com/@srijancse/how-real-time-collaborative-editing-work-operational-transformation-ac4902d75682
15. So why OT then?
• It can resolve all types of conflicts in an acceptable way
without human intervention
• It is good at preserving intention of changes
• It works well with a central source of state
• It can handle offline working ok
• Works well with a series of changes as the source of truth
• It is relatively easy to reason about
17. Why JSON Patch
• JSON Patch is a format for describing changes to a JSON
document
• We need to standardise how we represent operations
• JSON Patch is serialisable, modifiable, familiar, readable
and reversible (if we record the old value)
• JSON Patch actually makes it much easier to visualise
and understand Operational Transformations
28. Open-source at Threads
Please follow @threads_eng on Twitter for
updates on open-source and meet-ups.
We recently had a meet-up with one of the top open source contributors
@gajus who was talking about his journey in open-source.
Watch the video and find out about future meet-ups
https://www.meetup.com/JavaScript-Open-source-Meetup/
or https://thrds.biz/meetup
@aziraphael <— me again…. All animated images from giphy.com