25. The task
You cannot use any existing libraries to do this.
You are the library creator
26. The task
For sake of simplicity place two lists on the
same page, simulating both of them being
in offline mode, and make synchronization
to happen on a button click
31. Node A Node B
Synchronize
Item 1
Hey! Here are my items:
[{“label”:”Item 1”,“done”:false}]
Hey! Here are my items:
[]
32. Node A Node B
Synchronize
Item 1
Hey! Here are my items:
[{“label”:”Item 1”,“done”:false}]
Hey! Here are my items:
[]
Run some merging logic Run some merging logic
33. Node A Node B
Synchronize
Item 1
Node A Node B
Item 1 Item 1
Hey! Here are my items:
[{“label”:”Item 1”,“done”:false}]
Hey! Here are my items:
[]
Run some merging logic Run some merging logic
34. Node A Node B
Synchronize
Item 1
Node A Node B
Item 1 Item 1
Hey! Here are my items:
[{“label”:”Item 1”,“done”:false}]
Hey! Here are my items:
[]
Run some merging logic Run some merging logic
Send the
whole state
35. Node A Node B
Synchronize
Item 1 Item 1
Problem
36. Node A Node B
Synchronize
Item 1 Item 1
Node A Node B
Item 1
Item 2
Problem
37. Node A Node B
Synchronize
Item 1 Item 1
Node A Node B
Item 1
Item 2
Problem
38. Node A Node B
Synchronize
Item 1 Item 1
Node A Node B
Item 1
Item 2
Node A Node B
Item 1
Item 2
Item 1
Item 2
Problem
40. Node A Node B
Synchronize
Item 1
Hey! Here are my changes:
[{“type”: “add”,“label”:”Item 1”,“done”:false}]
Hey! Here are my changes:
[]
41. Node A Node B
Synchronize
Item 1
Hey! Here are my changes:
[{“type”: “add”,“label”:”Item 1”,“done”:false}]
Hey! Here are my changes:
[]
Apply received changes Apply received changes
42. Node A Node B
Synchronize
Item 1
Node A Node B
Item 1 Item 1
Hey! Here are my changes:
[{“type”: “add”,“label”:”Item 1”,“done”:false}]
Hey! Here are my changes:
[]
Apply received changes Apply received changes
43. Node A Node B
Synchronize
Item 1
Node A Node B
Item 1 Item 1
Hey! Here are my changes:
[{“type”: “add”,“label”:”Item 1”,“done”:false}]
Hey! Here are my changes:
[]
Apply received changes Apply received changes
Send all
local changes
63. Happened-before relation
Node A Node B
A
A`
Time Time
B
B`
A < A`
Partial order
B < B`
Incomparable (concurrent changes)
A || B A` || B`
A < B` B < A`
64. Happened-before relation
Node A Node B
A
A`
Time Time
B
B`
A < A`
Partial order
B < B`
Incomparable (concurrent changes)
A || B A` || B`
A < B` B < A`
86. OT - cons and pros
“Operations can be applied in any order
so we don’t have to care about timing”
87. OT - cons and pros
“OT approach of defining operations
through their offsets … raise serious
issues… resulting combinations of
states and operations are extremely
hard to foresee and understand”
88. OT - cons and pros
"Unfortunately, implementing OT sucks.
There's a million algorithms with
different tradeoffs, mostly trapped in
academic papers.”
89. OT - cons and pros
dOPT
Ellis & Gibbs 1989
adOPTed
Ressel et al. 1996
IMDR
Imine et al. 2003
Jupiter
Nichols et al. 1995
SOCT2
Suleiman et al. 1997
SDT
Li & Li 2004
SOCT3/4
Vidot et al. 2000
TTF
Oster et al. 2006 Credit: Martin Kleppmann
https://www.youtube.com/watch?v=B5NULPSiOGw&t=915s
90. OT - cons and pros
dOPT
Ellis & Gibbs 1989
adOPTed
Ressel et al. 1996
IMDR
Imine et al. 2003
Jupiter
Nichols et al. 1995
SOCT2
Suleiman et al. 1997
SDT
Li & Li 2004
SOCT3/4
Vidot et al. 2000
TTF
Oster et al. 2006
Require
central
server
Credit: Martin Kleppmann
https://www.youtube.com/watch?v=B5NULPSiOGw&t=915s
93. Item 1
Item 2
Unique ID
Unique ID
Item 3 Unique ID
Di
ff
erent algorithms generate IDs in di
ff
erent ways:
Binary tree path, integer + replica ID pair, vectors, logical clock timestamp etc…
111. Item 1 500
0
1000
Item 2 500
0
1000
Item 1 485
0
1000
Item 2 485
0
1000
1000/2 = 500
min = 500-100 = 400
max = 500+100 = 600
id = rand(min, max)
If we still pick randomly the same ID, then we fall back to
other way of sorting, for example node ID
Node A Node B