SlideShare a Scribd company logo
1 of 28
Download to read offline
Transformational
Operations!
Operational
Transformations!Concurrent Editing with JSON Patch and
Who am I, and what
am I doing here?
https://giphy.com
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.
https://giphy.com
Concurrent Editing with
JSON Patch and
Operational Transformation
https://giphy.com
What is
concurrent editing?
https://giphy.com
https://giphy.com
This must be a solved
problem, right?
https://giphy.com
What did we want
https://giphy.com
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
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
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
ABC
XABC
insert(0, ‘X’)
ABYC
insert(2, ‘Y’)
XABYC
insert(3, ‘Y’)
insert(0, ‘X’)
ServerClient 1 Client 2
XABYC
insert(3, ‘Y’)
XABYC
insert(3, ‘Y’)
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
JSON Patch
{
op: ‘add’,
path: ‘/title’,
value: ‘First title’
}
{
op: ‘replace’,
path: ‘/title’,
value: ‘A new title’
}
{
op: ‘add’,
path: ‘/names/3’,
value: ‘Jason’
}
{
op: ‘move’,
path: ‘/names/0’,
from: ‘/names/3’
}
{
op: ‘remove’,
path: ‘/names/2’
}
{
op: ‘copy’,
path: ‘/names/-’,
from: ‘/names/3’
}
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
How it works between
server and client
Actually list of changes
@threads/json-patch-ot
• JSON Patch OT lib

https://github.com/ThreadsStyling/json-patch-ot/

• npm install @threads/json-patch-ot

• Example client/server project

https://github.com/jasoniangreen/json-patch-ot-example
<Book
onMoveUp={changeHandler("move", `/books/${i - 1}`, `/books/${i}`)}
onMoveDown={changeHandler("move", `/books/${i + 1}`, `/books/${i}`)}
onDelete={changeHandler("remove", `/books/${i}`)}
onTitleChange={changeHandler("replace", `/books/${i}/title`)}
onAuthorChange={changeHandler("replace", `/books/${i}/author`)}
onColorChange={changeHandler("replace", `/books/${i}/color`)}
onInStockChange={changeHandler("replace", `/books/${i}/inStock`)}
onAddAfter={() =>
changeHandler("add", `/books/${i + 1}`)(EMPTY_ENTRY)
}
… etc …
/>
router.get("/", async ctx => {
const [result] = applyPatch({}, deepClone(operations.get()));
ctx.body = {
state: result.newDocument,
lastKnownOperationId: operations.get().length - 1
};
});
router.post("/", async ctx => {
const lastKnownOperationId: number =
ctx.request.body.lastKnownOperationId;
const patch: Operation[] = ctx.request.body.patch;
const unknownChanges = operations.get().slice(lastKnownOperationId + 1);
const transformedPatch = jsonPatchOT(unknownChanges, patch, {
acceptedWinsOnEqualPath: false
});
operations.push(...transformedPatch);
ctx.body = {
changesToApply: [...unknownChanges, ...transformedPatch],
lastKnownOperationId: operations.get().length - 1
};
});
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

More Related Content

Similar to Concurrent Editing with Operational Transformations and JSON Patch

Make everything realtime & collaborative - JS Summit 2014
Make everything realtime & collaborative - JS Summit 2014Make everything realtime & collaborative - JS Summit 2014
Make everything realtime & collaborative - JS Summit 2014
Joseph Gentle
 

Similar to Concurrent Editing with Operational Transformations and JSON Patch (20)

Make everything realtime & collaborative - JS Summit 2014
Make everything realtime & collaborative - JS Summit 2014Make everything realtime & collaborative - JS Summit 2014
Make everything realtime & collaborative - JS Summit 2014
 
The future will be Realtime & Collaborative
The future will be Realtime & CollaborativeThe future will be Realtime & Collaborative
The future will be Realtime & Collaborative
 
Puppet – Make stateful apps easier than stateless
Puppet – Make stateful apps easier than statelessPuppet – Make stateful apps easier than stateless
Puppet – Make stateful apps easier than stateless
 
An Introduction to React -- FED Date -- IBM Design
An Introduction to React -- FED Date -- IBM DesignAn Introduction to React -- FED Date -- IBM Design
An Introduction to React -- FED Date -- IBM Design
 
Systems Monitoring with Prometheus (Devops Ireland April 2015)
Systems Monitoring with Prometheus (Devops Ireland April 2015)Systems Monitoring with Prometheus (Devops Ireland April 2015)
Systems Monitoring with Prometheus (Devops Ireland April 2015)
 
The Next Five Years of Rails
The Next Five Years of RailsThe Next Five Years of Rails
The Next Five Years of Rails
 
Decoupling Edutopia.org
Decoupling Edutopia.orgDecoupling Edutopia.org
Decoupling Edutopia.org
 
Json to json esb transformation
Json to json esb transformationJson to json esb transformation
Json to json esb transformation
 
Transformation jsontojsonesb
Transformation jsontojsonesbTransformation jsontojsonesb
Transformation jsontojsonesb
 
Switch to Backend 2023
Switch to Backend 2023Switch to Backend 2023
Switch to Backend 2023
 
Web Service and Mobile Integrated Day I
Web Service and Mobile Integrated Day IWeb Service and Mobile Integrated Day I
Web Service and Mobile Integrated Day I
 
Collab365 Oct 2015 - Moving from SOAP to REST – You’ll Have to Do It Sometime
Collab365 Oct 2015 - Moving from SOAP to REST – You’ll Have to Do It SometimeCollab365 Oct 2015 - Moving from SOAP to REST – You’ll Have to Do It Sometime
Collab365 Oct 2015 - Moving from SOAP to REST – You’ll Have to Do It Sometime
 
ChatGPT and AI for web developers - Maximiliano Firtman
ChatGPT and AI for web developers - Maximiliano FirtmanChatGPT and AI for web developers - Maximiliano Firtman
ChatGPT and AI for web developers - Maximiliano Firtman
 
"Real-time Collaborative Text Editing on Grammarly’s Front-End Team" Oleksii...
 "Real-time Collaborative Text Editing on Grammarly’s Front-End Team" Oleksii... "Real-time Collaborative Text Editing on Grammarly’s Front-End Team" Oleksii...
"Real-time Collaborative Text Editing on Grammarly’s Front-End Team" Oleksii...
 
Untangling - fall2017 - week 9
Untangling - fall2017 - week 9Untangling - fall2017 - week 9
Untangling - fall2017 - week 9
 
Transformation jsontojsonesb
Transformation jsontojsonesbTransformation jsontojsonesb
Transformation jsontojsonesb
 
Json to json transformation in mule
Json to json transformation in muleJson to json transformation in mule
Json to json transformation in mule
 
Transformation jsontojsonesb
Transformation jsontojsonesbTransformation jsontojsonesb
Transformation jsontojsonesb
 
Python tools for testing web services over HTTP
Python tools for testing web services over HTTPPython tools for testing web services over HTTP
Python tools for testing web services over HTTP
 
Json to json transformation in mule
Json to json transformation in muleJson to json transformation in mule
Json to json transformation in mule
 

Recently uploaded

原版定制(Glasgow毕业证书)英国格拉斯哥大学毕业证原件一模一样
原版定制(Glasgow毕业证书)英国格拉斯哥大学毕业证原件一模一样原版定制(Glasgow毕业证书)英国格拉斯哥大学毕业证原件一模一样
原版定制(Glasgow毕业证书)英国格拉斯哥大学毕业证原件一模一样
AS
 
原版定制(LBS毕业证书)英国伦敦商学院毕业证原件一模一样
原版定制(LBS毕业证书)英国伦敦商学院毕业证原件一模一样原版定制(LBS毕业证书)英国伦敦商学院毕业证原件一模一样
原版定制(LBS毕业证书)英国伦敦商学院毕业证原件一模一样
AS
 
@OBAT ABORSI 3 BULAN@ OBAT PENGGUGUR KANDUNGAN 3 BULAN (087776558899)
@OBAT ABORSI 3 BULAN@ OBAT PENGGUGUR KANDUNGAN 3 BULAN (087776558899)@OBAT ABORSI 3 BULAN@ OBAT PENGGUGUR KANDUNGAN 3 BULAN (087776558899)
@OBAT ABORSI 3 BULAN@ OBAT PENGGUGUR KANDUNGAN 3 BULAN (087776558899)
Obat Cytotec
 
如何办理(UCLA毕业证)加州大学洛杉矶分校毕业证成绩单本科硕士学位证留信学历认证
如何办理(UCLA毕业证)加州大学洛杉矶分校毕业证成绩单本科硕士学位证留信学历认证如何办理(UCLA毕业证)加州大学洛杉矶分校毕业证成绩单本科硕士学位证留信学历认证
如何办理(UCLA毕业证)加州大学洛杉矶分校毕业证成绩单本科硕士学位证留信学历认证
hfkmxufye
 
一比一定制加州大学欧文分校毕业证学位证书
一比一定制加州大学欧文分校毕业证学位证书一比一定制加州大学欧文分校毕业证学位证书
一比一定制加州大学欧文分校毕业证学位证书
A
 
Jual obat aborsi Bekasi ( 085657271886 ) Cytote pil telat bulan penggugur kan...
Jual obat aborsi Bekasi ( 085657271886 ) Cytote pil telat bulan penggugur kan...Jual obat aborsi Bekasi ( 085657271886 ) Cytote pil telat bulan penggugur kan...
Jual obat aborsi Bekasi ( 085657271886 ) Cytote pil telat bulan penggugur kan...
ZurliaSoop
 
一比一原版美国北卡罗莱纳大学毕业证如何办理
一比一原版美国北卡罗莱纳大学毕业证如何办理一比一原版美国北卡罗莱纳大学毕业证如何办理
一比一原版美国北卡罗莱纳大学毕业证如何办理
A
 
一比一原版田纳西大学毕业证如何办理
一比一原版田纳西大学毕业证如何办理一比一原版田纳西大学毕业证如何办理
一比一原版田纳西大学毕业证如何办理
F
 
一比一原版英国格林多大学毕业证如何办理
一比一原版英国格林多大学毕业证如何办理一比一原版英国格林多大学毕业证如何办理
一比一原版英国格林多大学毕业证如何办理
AS
 
一比一原版(毕业证书)新西兰怀特克利夫艺术设计学院毕业证原件一模一样
一比一原版(毕业证书)新西兰怀特克利夫艺术设计学院毕业证原件一模一样一比一原版(毕业证书)新西兰怀特克利夫艺术设计学院毕业证原件一模一样
一比一原版(毕业证书)新西兰怀特克利夫艺术设计学院毕业证原件一模一样
AS
 
原版定制美国加州大学河滨分校毕业证原件一模一样
原版定制美国加州大学河滨分校毕业证原件一模一样原版定制美国加州大学河滨分校毕业证原件一模一样
原版定制美国加州大学河滨分校毕业证原件一模一样
A
 
一比一原版(UWE毕业证书)西英格兰大学毕业证原件一模一样
一比一原版(UWE毕业证书)西英格兰大学毕业证原件一模一样一比一原版(UWE毕业证书)西英格兰大学毕业证原件一模一样
一比一原版(UWE毕业证书)西英格兰大学毕业证原件一模一样
Fi
 
一比一原版(Polytechnic毕业证书)新加坡理工学院毕业证原件一模一样
一比一原版(Polytechnic毕业证书)新加坡理工学院毕业证原件一模一样一比一原版(Polytechnic毕业证书)新加坡理工学院毕业证原件一模一样
一比一原版(Polytechnic毕业证书)新加坡理工学院毕业证原件一模一样
AS
 

Recently uploaded (20)

The Rise of Subscription-Based Digital Services.pdf
The Rise of Subscription-Based Digital Services.pdfThe Rise of Subscription-Based Digital Services.pdf
The Rise of Subscription-Based Digital Services.pdf
 
原版定制(Glasgow毕业证书)英国格拉斯哥大学毕业证原件一模一样
原版定制(Glasgow毕业证书)英国格拉斯哥大学毕业证原件一模一样原版定制(Glasgow毕业证书)英国格拉斯哥大学毕业证原件一模一样
原版定制(Glasgow毕业证书)英国格拉斯哥大学毕业证原件一模一样
 
原版定制(LBS毕业证书)英国伦敦商学院毕业证原件一模一样
原版定制(LBS毕业证书)英国伦敦商学院毕业证原件一模一样原版定制(LBS毕业证书)英国伦敦商学院毕业证原件一模一样
原版定制(LBS毕业证书)英国伦敦商学院毕业证原件一模一样
 
HUMANIZE YOUR BRAND - FREE E-WORKBOOK Download Now
HUMANIZE YOUR BRAND - FREE E-WORKBOOK Download NowHUMANIZE YOUR BRAND - FREE E-WORKBOOK Download Now
HUMANIZE YOUR BRAND - FREE E-WORKBOOK Download Now
 
@OBAT ABORSI 3 BULAN@ OBAT PENGGUGUR KANDUNGAN 3 BULAN (087776558899)
@OBAT ABORSI 3 BULAN@ OBAT PENGGUGUR KANDUNGAN 3 BULAN (087776558899)@OBAT ABORSI 3 BULAN@ OBAT PENGGUGUR KANDUNGAN 3 BULAN (087776558899)
@OBAT ABORSI 3 BULAN@ OBAT PENGGUGUR KANDUNGAN 3 BULAN (087776558899)
 
APNIC Policy Roundup presented by Sunny Chendi at TWNOG 5.0
APNIC Policy Roundup presented by Sunny Chendi at TWNOG 5.0APNIC Policy Roundup presented by Sunny Chendi at TWNOG 5.0
APNIC Policy Roundup presented by Sunny Chendi at TWNOG 5.0
 
如何办理(UCLA毕业证)加州大学洛杉矶分校毕业证成绩单本科硕士学位证留信学历认证
如何办理(UCLA毕业证)加州大学洛杉矶分校毕业证成绩单本科硕士学位证留信学历认证如何办理(UCLA毕业证)加州大学洛杉矶分校毕业证成绩单本科硕士学位证留信学历认证
如何办理(UCLA毕业证)加州大学洛杉矶分校毕业证成绩单本科硕士学位证留信学历认证
 
一比一定制加州大学欧文分校毕业证学位证书
一比一定制加州大学欧文分校毕业证学位证书一比一定制加州大学欧文分校毕业证学位证书
一比一定制加州大学欧文分校毕业证学位证书
 
Jual obat aborsi Bekasi ( 085657271886 ) Cytote pil telat bulan penggugur kan...
Jual obat aborsi Bekasi ( 085657271886 ) Cytote pil telat bulan penggugur kan...Jual obat aborsi Bekasi ( 085657271886 ) Cytote pil telat bulan penggugur kan...
Jual obat aborsi Bekasi ( 085657271886 ) Cytote pil telat bulan penggugur kan...
 
一比一原版美国北卡罗莱纳大学毕业证如何办理
一比一原版美国北卡罗莱纳大学毕业证如何办理一比一原版美国北卡罗莱纳大学毕业证如何办理
一比一原版美国北卡罗莱纳大学毕业证如何办理
 
一比一原版田纳西大学毕业证如何办理
一比一原版田纳西大学毕业证如何办理一比一原版田纳西大学毕业证如何办理
一比一原版田纳西大学毕业证如何办理
 
一比一原版英国格林多大学毕业证如何办理
一比一原版英国格林多大学毕业证如何办理一比一原版英国格林多大学毕业证如何办理
一比一原版英国格林多大学毕业证如何办理
 
TOP 100 Vulnerabilities Step-by-Step Guide Handbook
TOP 100 Vulnerabilities Step-by-Step Guide HandbookTOP 100 Vulnerabilities Step-by-Step Guide Handbook
TOP 100 Vulnerabilities Step-by-Step Guide Handbook
 
一比一原版(毕业证书)新西兰怀特克利夫艺术设计学院毕业证原件一模一样
一比一原版(毕业证书)新西兰怀特克利夫艺术设计学院毕业证原件一模一样一比一原版(毕业证书)新西兰怀特克利夫艺术设计学院毕业证原件一模一样
一比一原版(毕业证书)新西兰怀特克利夫艺术设计学院毕业证原件一模一样
 
Beyond Inbound: Unlocking the Secrets of API Egress Traffic Management
Beyond Inbound: Unlocking the Secrets of API Egress Traffic ManagementBeyond Inbound: Unlocking the Secrets of API Egress Traffic Management
Beyond Inbound: Unlocking the Secrets of API Egress Traffic Management
 
原版定制美国加州大学河滨分校毕业证原件一模一样
原版定制美国加州大学河滨分校毕业证原件一模一样原版定制美国加州大学河滨分校毕业证原件一模一样
原版定制美国加州大学河滨分校毕业证原件一模一样
 
Abortion Pills In Jeddah+966572737505 & Get cytotec Jeddah
Abortion Pills In Jeddah+966572737505 & Get cytotec JeddahAbortion Pills In Jeddah+966572737505 & Get cytotec Jeddah
Abortion Pills In Jeddah+966572737505 & Get cytotec Jeddah
 
[Hackersuli] Élő szövet a fémvázon: Python és gépi tanulás a Zeek platformon
[Hackersuli] Élő szövet a fémvázon: Python és gépi tanulás a Zeek platformon[Hackersuli] Élő szövet a fémvázon: Python és gépi tanulás a Zeek platformon
[Hackersuli] Élő szövet a fémvázon: Python és gépi tanulás a Zeek platformon
 
一比一原版(UWE毕业证书)西英格兰大学毕业证原件一模一样
一比一原版(UWE毕业证书)西英格兰大学毕业证原件一模一样一比一原版(UWE毕业证书)西英格兰大学毕业证原件一模一样
一比一原版(UWE毕业证书)西英格兰大学毕业证原件一模一样
 
一比一原版(Polytechnic毕业证书)新加坡理工学院毕业证原件一模一样
一比一原版(Polytechnic毕业证书)新加坡理工学院毕业证原件一模一样一比一原版(Polytechnic毕业证书)新加坡理工学院毕业证原件一模一样
一比一原版(Polytechnic毕业证书)新加坡理工学院毕业证原件一模一样
 

Concurrent Editing with Operational Transformations and JSON Patch

  • 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.
  • 6. Concurrent Editing with JSON Patch and Operational Transformation https://giphy.com
  • 9. This must be a solved problem, right? https://giphy.com
  • 10. What did we want https://giphy.com
  • 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
  • 14. ABC XABC insert(0, ‘X’) ABYC insert(2, ‘Y’) XABYC insert(3, ‘Y’) insert(0, ‘X’) ServerClient 1 Client 2 XABYC insert(3, ‘Y’) XABYC insert(3, ‘Y’)
  • 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
  • 16. JSON Patch { op: ‘add’, path: ‘/title’, value: ‘First title’ } { op: ‘replace’, path: ‘/title’, value: ‘A new title’ } { op: ‘add’, path: ‘/names/3’, value: ‘Jason’ } { op: ‘move’, path: ‘/names/0’, from: ‘/names/3’ } { op: ‘remove’, path: ‘/names/2’ } { op: ‘copy’, path: ‘/names/-’, from: ‘/names/3’ }
  • 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
  • 18. How it works between server and client
  • 19. Actually list of changes
  • 20.
  • 21.
  • 22.
  • 23.
  • 24. @threads/json-patch-ot • JSON Patch OT lib
 https://github.com/ThreadsStyling/json-patch-ot/ • npm install @threads/json-patch-ot • Example client/server project
 https://github.com/jasoniangreen/json-patch-ot-example
  • 25. <Book onMoveUp={changeHandler("move", `/books/${i - 1}`, `/books/${i}`)} onMoveDown={changeHandler("move", `/books/${i + 1}`, `/books/${i}`)} onDelete={changeHandler("remove", `/books/${i}`)} onTitleChange={changeHandler("replace", `/books/${i}/title`)} onAuthorChange={changeHandler("replace", `/books/${i}/author`)} onColorChange={changeHandler("replace", `/books/${i}/color`)} onInStockChange={changeHandler("replace", `/books/${i}/inStock`)} onAddAfter={() => changeHandler("add", `/books/${i + 1}`)(EMPTY_ENTRY) } … etc … />
  • 26. router.get("/", async ctx => { const [result] = applyPatch({}, deepClone(operations.get())); ctx.body = { state: result.newDocument, lastKnownOperationId: operations.get().length - 1 }; });
  • 27. router.post("/", async ctx => { const lastKnownOperationId: number = ctx.request.body.lastKnownOperationId; const patch: Operation[] = ctx.request.body.patch; const unknownChanges = operations.get().slice(lastKnownOperationId + 1); const transformedPatch = jsonPatchOT(unknownChanges, patch, { acceptedWinsOnEqualPath: false }); operations.push(...transformedPatch); ctx.body = { changesToApply: [...unknownChanges, ...transformedPatch], lastKnownOperationId: operations.get().length - 1 }; });
  • 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