SlideShare a Scribd company logo
1 of 48
RICH COLLABORATIVE DATA
STRUCTURES FOR EVERYONE
INTRODUCTION
Bartosz Sypytkowski
▪ @Horusiath
▪ b.sypytkowski@gmail.com
▪ bartoszsypytkowski.com
 Motivation & challenges
 Timestamps and concurrency tracking
 Deterministic conflict resolution
 Optimizations
AGENDA
PROBLEM STATEMENT
COLLABORATIVE TEXT EDITOR
COLLABORATIVE
TEXT EDITOR
Alice
a
Carol
a
Bob
a
COLLABORATIVE
TEXT EDITOR
Alice
a
Carol
a
Bob
a
insert(1, ‘b’) insert(1, ‘c’)
COLLABORATIVE
TEXT EDITOR
Alice
a
Carol
ac
Bob
ab
COLLABORATIVE
TEXT EDITOR
Alice
a
Carol
ac
Bob
ab
insert(1, ‘b’)
insert(1, ‘c’)
COLLABORATIVE
TEXT EDITOR
Alice
abc
Carol
abc
Bob
acb
MAYBE JUST SYNCHRONIZE VIA CENTRAL SERVER?
SERVER-DRIVEN
TEXT EDITOR
Alice
a
Carol
a
Bob
a
server
a
SERVER-DRIVEN
TEXT EDITOR
Alice
a
Carol
a
Bob
a
server
a
insert(1, ‘b’) insert(1, ‘c’)
SERVER-DRIVEN
TEXT EDITOR
Alice
a
Carol
a
Bob
a
server
a
insert(1, ‘b’) insert(1, ‘c’)
E1 E2
SERVER-DRIVEN
TEXT EDITOR
Alice
a
Carol
a
Bob
a
server
ab
E2
insert(1,
‘b’)
SERVER-DRIVEN
TEXT EDITOR
Alice
ab
Carol
ab
Bob
ab
server
acb
insert(1,
‘c’)
SERVER-DRIVEN
TEXT EDITOR
Alice
acb
Carol
acb
Bob
acb
server
acb
COMPAR
ING
VECTOR
CLOCKS
ISSUES
1. Latency
2. Online-only / Network issues
3. Characters interleaving
4. Server: bottleneck & point of failure
FIELDS SHARING
SIMILAR
PROBLEMS
1. Collaborative text editors
2. Cross-continental data replication
3. Vehicle apps
4. Remote areas
CONFLICT AVOIDANCE
“Let the majority decide on
the correct order.”
Decisions are made by
quorum
CONFLICT AVOIDANCE CONFLICT RESOLUTION
“Let the majority decide on
the correct order.”
“Given enough context
everyone should come to the
same conclusion.”
Decisions are made by
quorum
Decisions are made
individually
CONFLICT RESOLUTION
IT’S ALL ABOUT PRESERVING THE ORIGINAL INTENT
DON’T USE INDEXES FOR POSITIONING
THEIR MEANING CHANGES OVER TIME
LAMPORT CLOCK
A:1
Unique peer ID
Sequence
Number
CONTEXT-AWARE
INSERTION
insert_between(A:1, B:1, (B:2, ‘b’))
CONTEXT-AWARE
INSERTION
insert_between(A:1, B:1, (B:2, ‘b’))
inserted block ID
inserted block
content
CONTEXT-AWARE
INSERTION
insert_between(A:1, B:1, (B:2, ‘b’))
left neighbor
right neighbor
inserted block ID
inserted block
content
CONFLICT RESOLUTION
A:1
ID
NULL
LEFT
NULL
RIGHT
CONTENT
“a”
STRING
B:1
ID
A:1
LEFT
NULL
RIGHT
CONTENT
“d”
STRING
Document state
B:2
ID
A:1
LEFT
B:1
RIGHT
CONTENT
“c”
STRING
A:2
ID
A:1
LEFT
B:1
RIGHT
CONTENT
“b”
STRING
CONFLICT
RESOLUTION
A:1
ID
NULL
LEFT
NULL
RIGHT
CONTENT
“a”
STRING
B:1
ID
A:1
LEFT
NULL
RIGHT
CONTENT
“d”
STRING
Document state
B:2
ID
A:1
LEFT
B:1
RIGHT
CONTENT
“c”
STRING
A:2
ID
A:1
LEFT
B:1
RIGHT
CONTENT
“b”
STRING
CONFLICT
RESOLUTION
A:1
ID
NULL
LEFT
NULL
RIGHT
CONTENT
“a”
STRING
B:1
ID
A:1
LEFT
NULL
RIGHT
CONTENT
“d”
STRING
Document state
B:2
ID
A:1
LEFT
B:1
RIGHT
CONTENT
“c”
STRING
A:2
ID
A:1
LEFT
B:1
RIGHT
CONTENT
“b”
STRING
CONFLICT
RESOLUTION
?
A:1
ID
NULL
LEFT
NULL
RIGHT
CONTENT
“a”
STRING
B:1
ID
A:1
LEFT
NULL
RIGHT
CONTENT
“d”
STRING
Document state
B:2
ID
A:1
LEFT
B:1
RIGHT
CONTENT
“c”
STRING
A:2
ID
A:1
LEFT
B:1
RIGHT
CONTENT
“b”
STRING
CONFLICT
RESOLUTION
Use block IDs to skip over blocks
with lower precedence
A:1
ID
NULL
LEFT
NULL
RIGHT
CONTENT
“a”
STRING
B:1
ID
A:1
LEFT
NULL
RIGHT
CONTENT
“d”
STRING
Document state
B:2
ID
A:1
LEFT
B:1
RIGHT
CONTENT
“c”
STRING
A:2
ID
A:1
LEFT
B:1
RIGHT
CONTENT
“b”
STRING
CONFLICT
RESOLUTION
OPTIMIZATIONS
CAUSE METADATA CAN BE HEAVY
OPTIMIZATIONS
BLOCK MERGING
A:1
ID
NULL
LEFT
NULL
RIGHT
CONTENT
“a”
STRING
A:2
ID
A:1
LEFT
NULL
RIGHT
CONTENT
“b”
STRING
Document state
OPTIMIZATIONS
BLOCK MERGING
A:1
ID
NULL
LEFT
NULL
RIGHT
CONTENT
“a”
STRING
A:2
ID
A:1
LEFT
NULL
RIGHT
CONTENT
“b”
STRING
Document state
Both blocks have sequential IDs
OPTIMIZATIONS
BLOCK MERGING
A:1
ID
NULL
LEFT
NULL
RIGHT
CONTENT
“a”
STRING
A:2
ID
A:1
LEFT
NULL
RIGHT
CONTENT
“b”
STRING
Document state
Block was intended to be placed
sequentially
OPTIMIZATIONS
BLOCK MERGING
A:1
ID
NULL
LEFT
NULL
RIGHT
CONTENT
“ab”
STRING
Document state
Block A:1 is responsible for holding 2
elements now (range from A:1 to A:2)
OPTIMIZATIONS
BLOCK MERGING
A:1
ID
NULL
LEFT
NULL
RIGHT
CONTENT
“ab”
STRING
A:3
ID
A:2
LEFT
NULL
RIGHT
CONTENT
“c”
STRING
Document state
Next block ID = last block ID + last
block length
insert_between(A:2, NULL, (A:3, ‘c’))
OPTIMIZATIONS
BLOCK MERGING
A:1
ID
NULL
LEFT
NULL
RIGHT
CONTENT
“ab”
STRING
A:3
ID
A:2
LEFT
NULL
RIGHT
CONTENT
“c”
STRING
Document state
Next block ID = last block ID + last
block length
insert_between(A:2, NULL, (A:3, ‘c’))
Left neighbor point to last ID
not block ID
WHAT IF WE WANT TO INSERT ELEMENT WITHIN BLOCK?
A:1
ID
NULL
LEFT
NULL
RIGHT
CONTENT
“helo”
STRING
A:5
ID
A:3
LEFT
A:4
RIGHT
CONTENT
“l”
STRING
Document state
insert_between(A:3, A:4, (A:5, ‘l’))
OPTIMIZATIONS
BLOCK SPLITTING
A:4
ID
A:3
LEFT
NULL
RIGHT
CONTENT
“o”
STRING
A:5
ID
A:3
LEFT
A:4
RIGHT
CONTENT
“l”
STRING
Document state
insert_between(A:3, A:4, (A:5, ‘l’))
OPTIMIZATIONS
BLOCK SPLITTING
A:1
ID
NULL
LEFT
A:4
RIGHT
CONTENT
“hel”
STRING
Split blocks to create space
A:4
ID
A:3
LEFT
NULL
RIGHT
CONTENT
“o”
STRING
A:5
ID
A:3
LEFT
A:4
RIGHT
CONTENT
“l”
STRING
Document state
OPTIMIZATIONS
BLOCK SPLITTING
A:1
ID
NULL
LEFT
A:4
RIGHT
CONTENT
“hel”
STRING
COMPAR
ING
VECTOR
CLOCKS
OTHER STUFF
1. Tombstones
2. Other data types eg. Maps, Counters
3. Undo/Redo
4. Transactions
SUMMARY
 Yjs/Yrs: https://crates.io/crates/yrs
 Automerge: https://automerge.org/
 Ditto.live: https://www.ditto.live/
 RiakDB: https://riak.com/
 Amazon DynamoDB: https://aws.amazon.com/dynamodb/
 AntidoteDB: https://www.antidotedb.eu/
CRDT PROJECTS
 CRDTs deep dive: https://bartoszsypytkowski.com/tag/crdt/
 List of aggregated CRDT articles: https://crdt.tech
 Making CRDTs faster: https://josephg.com/blog/crdts-go-brrr/
REFERENCES
THANK YOU

More Related Content

More from Bartosz Sypytkowski

Virtual machines - how they work
Virtual machines - how they workVirtual machines - how they work
Virtual machines - how they workBartosz Sypytkowski
 
Akka.NET streams and reactive streams
Akka.NET streams and reactive streamsAkka.NET streams and reactive streams
Akka.NET streams and reactive streamsBartosz Sypytkowski
 
GraphQL - an elegant weapon... for more civilized age
GraphQL - an elegant weapon... for more civilized ageGraphQL - an elegant weapon... for more civilized age
GraphQL - an elegant weapon... for more civilized ageBartosz Sypytkowski
 

More from Bartosz Sypytkowski (6)

Virtual machines - how they work
Virtual machines - how they workVirtual machines - how they work
Virtual machines - how they work
 
Short story of time
Short story of timeShort story of time
Short story of time
 
Akka.NET streams and reactive streams
Akka.NET streams and reactive streamsAkka.NET streams and reactive streams
Akka.NET streams and reactive streams
 
Collaborative text editing
Collaborative text editingCollaborative text editing
Collaborative text editing
 
The last mile from db to disk
The last mile from db to diskThe last mile from db to disk
The last mile from db to disk
 
GraphQL - an elegant weapon... for more civilized age
GraphQL - an elegant weapon... for more civilized ageGraphQL - an elegant weapon... for more civilized age
GraphQL - an elegant weapon... for more civilized age
 

Recently uploaded

ManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide DeckManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide DeckManageIQ
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfonteinmasabamasaba
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024Mind IT Systems
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park masabamasaba
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech studentsHimanshiGarg82
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrainmasabamasaba
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfayushiqss
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verifiedSector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verifiedDelhi Call girls
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...Jittipong Loespradit
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfproinshot.com
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 

Recently uploaded (20)

ManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide DeckManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide Deck
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verifiedSector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 

Rich collaborative data structures for everyone