SlideShare a Scribd company logo
CRDT Data Structures
And their real world uses
Distributed counter (motivation example)
Problem
20 20
+1 +1
21 21 21 21
The problem
Several active servers
Semi-online systems (navigators, sales support software)
Distributed systems (replication in general)
Consistency
… all nodes see the same data at the same time ..
A A
Consistency has costs
Consistency
Eventual consistency
“ …. eventually all accesses to that item will return the last updated value … “
Strong eventual consistency
“... any two nodes that have received the same (unordered) set of updates will be in the same state … “
CRDT
Conflict-free Replicated Data Type
CvRDT (Convergent) aka 'state-based objects'
CmRDT (Commutative) aka 'ops-based objects'
First CRDT: G-Counter
{a:4,b:5} {a:4,b:5}
+1 +1
{a:5,b:5} {a:4,b:6} {a:5,b:6} {a:5,b:6}
Value of the counter - sum of all parts
CRDT counter: alternative
20 20
+1 +1
21 21
+1
+1
22 22
G-Counter extension: PN-Counter
What if decrement operation is also required?
Use two g-counters: one for increments, another for decrements
State based vs ops based
State based:
Merge should be: associative, commutative and idempotent
(A ⨂ B) ⨂ C= A ⨂ (B ⨂ C) max(max(1, 2), 3) = max(1, max(2, 3))
A ⨂ B = B ⨂ A max(1, 2) = max(2, 1)
A ⨂ B = A ⨂ B ⨂ B max(1, 2) = max(max(1, 2), 2)
State based vs ops based
Ops based:
Replication channels should have exactly-once semantic and support causal
ordering
21 21
+1
Concurrent operations should commute
A B
C D
Example: Cassandra
Cassandra’s distributed counters are implemented as PN-counters (almost)
Cassandra’s general replication is implemented as another CRDT (LWW-Register)
(data1,12) (data2,14) (data2,14) (data2,14)
MV-Register (multi value)
Vector clock
Very similar to g-counter - {a:100, b: 98, c: 101}
Each operation on server increments corresponding value
Merge takes maximum of correlated elements
One event is AFTER another if vector clock of one is less than vector clock
of another:
{a: 10, b: 11, c: 12} < {a:10, b:12, c:12}
MV-Register
Value is stored and replicated with vector clock
On merge if one vector clock is bigger than another then keep value with
bigger vector clock
Otherwise keep both and let client choose which one to keep
Example: Riak
It uses MV-Register for general replication if multi-value mode is enabled
It uses LWW-Register otherwise
PN-counter is used to implement distributed counters
Other CRDTs are also used (Sets, flags)
G-Set (Grow only)
Merge operation is set union, which is idempotent, commutative and associative
Only add operation is supported
OR-Set (observed remove)
Idea is to use two sets for added and removed items, but...
Store them with some unique id. Such id should be assigned during adding of
element
(a, id1)
(a, id2)
(b, id3)
(c, id4)
‘Added’ Set
(b, id3)
‘Removed’ Set
(a, id2)
Element is eligible to remove only if it is in ‘added’ set with same id
Real life example: TomTom (navigators)
Challenges:
Account data (like favorites) can be modified from different devices
concurrently
Device can be offline during adding new information
Huge number of accounts
Real life example: TomTom (navigators)
CRDT to rescue!
They use combination of CRDT: MV-Register + modified OR-Set (OUR-Set)
*Original image from TomTom’s presentation
Real life example: Swarm.js
Swarm is a reactive data sync library and middleware
Swarm uses CRDT to merge data
Real life example: Spark’s accumulator
Docblock of Accumulable class
A data type that can be accumulated, ie has an commutative and associative "add" operation
You must define how to add data, and how to merge two of these together
It seems like CRDT!
Q/A

More Related Content

Similar to Crdt and their uses. SE 2016

最新のデータベース技術の方向性で思うこと
最新のデータベース技術の方向性で思うこと最新のデータベース技術の方向性で思うこと
最新のデータベース技術の方向性で思うこと
Masayoshi Hagiwara
 
R studio
R studio R studio
R studio
Kinza Irshad
 
Javascript & SQL within database management system
Javascript & SQL within database management systemJavascript & SQL within database management system
Javascript & SQL within database management system
Clusterpoint
 
CRDB - Multi-Master Geo Distributed Redis with Redis Enterprise
CRDB - Multi-Master Geo Distributed Redis with Redis EnterpriseCRDB - Multi-Master Geo Distributed Redis with Redis Enterprise
CRDB - Multi-Master Geo Distributed Redis with Redis Enterprise
Elad Ash
 
How to provide enterprise high availability with MariaDB Platform
How to provide enterprise high availability with MariaDB PlatformHow to provide enterprise high availability with MariaDB Platform
How to provide enterprise high availability with MariaDB Platform
ssuser2fa8b4
 
Accelerating analytics on the Sensor and IoT Data.
Accelerating analytics on the Sensor and IoT Data. Accelerating analytics on the Sensor and IoT Data.
Accelerating analytics on the Sensor and IoT Data.
Keshav Murthy
 
Analyzing On-Chip Interconnect with Modern C++
Analyzing On-Chip Interconnect with Modern C++Analyzing On-Chip Interconnect with Modern C++
Analyzing On-Chip Interconnect with Modern C++
Jeff Trull
 
Direct policy search
Direct policy searchDirect policy search
Direct policy search
Olivier Teytaud
 
Stratosphere Intro (Java and Scala Interface)
Stratosphere Intro (Java and Scala Interface)Stratosphere Intro (Java and Scala Interface)
Stratosphere Intro (Java and Scala Interface)
Robert Metzger
 
Transformations and actions a visual guide training
Transformations and actions a visual guide trainingTransformations and actions a visual guide training
Transformations and actions a visual guide training
Spark Summit
 
OdessaJS 2017: Groupware Systems for fun and profit
OdessaJS 2017: Groupware Systems for fun and profitOdessaJS 2017: Groupware Systems for fun and profit
OdessaJS 2017: Groupware Systems for fun and profit
Max Klymyshyn
 
Exploring Microoptimizations Using Tizen Code as an Example
Exploring Microoptimizations Using Tizen Code as an ExampleExploring Microoptimizations Using Tizen Code as an Example
Exploring Microoptimizations Using Tizen Code as an Example
PVS-Studio
 
Parallel Implementation of K Means Clustering on CUDA
Parallel Implementation of K Means Clustering on CUDAParallel Implementation of K Means Clustering on CUDA
Parallel Implementation of K Means Clustering on CUDA
prithan
 
Anais Dotis-Georgiou & Faith Chikwekwe [InfluxData] | Top 10 Hurdles for Flux...
Anais Dotis-Georgiou & Faith Chikwekwe [InfluxData] | Top 10 Hurdles for Flux...Anais Dotis-Georgiou & Faith Chikwekwe [InfluxData] | Top 10 Hurdles for Flux...
Anais Dotis-Georgiou & Faith Chikwekwe [InfluxData] | Top 10 Hurdles for Flux...
InfluxData
 
GBM in H2O with Cliff Click: H2O API
GBM in H2O with Cliff Click: H2O APIGBM in H2O with Cliff Click: H2O API
GBM in H2O with Cliff Click: H2O API
Sri Ambati
 
Parallel Computing 2007: Bring your own parallel application
Parallel Computing 2007: Bring your own parallel applicationParallel Computing 2007: Bring your own parallel application
Parallel Computing 2007: Bring your own parallel application
Geoffrey Fox
 
20181212 - PGconfASIA - LT - English
20181212 - PGconfASIA - LT - English20181212 - PGconfASIA - LT - English
20181212 - PGconfASIA - LT - English
Kohei KaiGai
 
Aggregation Functions in OCL
Aggregation Functions in OCL Aggregation Functions in OCL
Aggregation Functions in OCL
Jordi Cabot
 
Sandy Ryza – Software Engineer, Cloudera at MLconf ATL
Sandy Ryza – Software Engineer, Cloudera at MLconf ATLSandy Ryza – Software Engineer, Cloudera at MLconf ATL
Sandy Ryza – Software Engineer, Cloudera at MLconf ATL
MLconf
 

Similar to Crdt and their uses. SE 2016 (20)

最新のデータベース技術の方向性で思うこと
最新のデータベース技術の方向性で思うこと最新のデータベース技術の方向性で思うこと
最新のデータベース技術の方向性で思うこと
 
R studio
R studio R studio
R studio
 
Javascript & SQL within database management system
Javascript & SQL within database management systemJavascript & SQL within database management system
Javascript & SQL within database management system
 
CRDB - Multi-Master Geo Distributed Redis with Redis Enterprise
CRDB - Multi-Master Geo Distributed Redis with Redis EnterpriseCRDB - Multi-Master Geo Distributed Redis with Redis Enterprise
CRDB - Multi-Master Geo Distributed Redis with Redis Enterprise
 
How to provide enterprise high availability with MariaDB Platform
How to provide enterprise high availability with MariaDB PlatformHow to provide enterprise high availability with MariaDB Platform
How to provide enterprise high availability with MariaDB Platform
 
Accelerating analytics on the Sensor and IoT Data.
Accelerating analytics on the Sensor and IoT Data. Accelerating analytics on the Sensor and IoT Data.
Accelerating analytics on the Sensor and IoT Data.
 
Analyzing On-Chip Interconnect with Modern C++
Analyzing On-Chip Interconnect with Modern C++Analyzing On-Chip Interconnect with Modern C++
Analyzing On-Chip Interconnect with Modern C++
 
Direct policy search
Direct policy searchDirect policy search
Direct policy search
 
Stratosphere Intro (Java and Scala Interface)
Stratosphere Intro (Java and Scala Interface)Stratosphere Intro (Java and Scala Interface)
Stratosphere Intro (Java and Scala Interface)
 
Dfd2
Dfd2Dfd2
Dfd2
 
Transformations and actions a visual guide training
Transformations and actions a visual guide trainingTransformations and actions a visual guide training
Transformations and actions a visual guide training
 
OdessaJS 2017: Groupware Systems for fun and profit
OdessaJS 2017: Groupware Systems for fun and profitOdessaJS 2017: Groupware Systems for fun and profit
OdessaJS 2017: Groupware Systems for fun and profit
 
Exploring Microoptimizations Using Tizen Code as an Example
Exploring Microoptimizations Using Tizen Code as an ExampleExploring Microoptimizations Using Tizen Code as an Example
Exploring Microoptimizations Using Tizen Code as an Example
 
Parallel Implementation of K Means Clustering on CUDA
Parallel Implementation of K Means Clustering on CUDAParallel Implementation of K Means Clustering on CUDA
Parallel Implementation of K Means Clustering on CUDA
 
Anais Dotis-Georgiou & Faith Chikwekwe [InfluxData] | Top 10 Hurdles for Flux...
Anais Dotis-Georgiou & Faith Chikwekwe [InfluxData] | Top 10 Hurdles for Flux...Anais Dotis-Georgiou & Faith Chikwekwe [InfluxData] | Top 10 Hurdles for Flux...
Anais Dotis-Georgiou & Faith Chikwekwe [InfluxData] | Top 10 Hurdles for Flux...
 
GBM in H2O with Cliff Click: H2O API
GBM in H2O with Cliff Click: H2O APIGBM in H2O with Cliff Click: H2O API
GBM in H2O with Cliff Click: H2O API
 
Parallel Computing 2007: Bring your own parallel application
Parallel Computing 2007: Bring your own parallel applicationParallel Computing 2007: Bring your own parallel application
Parallel Computing 2007: Bring your own parallel application
 
20181212 - PGconfASIA - LT - English
20181212 - PGconfASIA - LT - English20181212 - PGconfASIA - LT - English
20181212 - PGconfASIA - LT - English
 
Aggregation Functions in OCL
Aggregation Functions in OCL Aggregation Functions in OCL
Aggregation Functions in OCL
 
Sandy Ryza – Software Engineer, Cloudera at MLconf ATL
Sandy Ryza – Software Engineer, Cloudera at MLconf ATLSandy Ryza – Software Engineer, Cloudera at MLconf ATL
Sandy Ryza – Software Engineer, Cloudera at MLconf ATL
 

Recently uploaded

GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
Neo4j
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
Neo4j
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
James Anderson
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
Pierluigi Pugliese
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 

Recently uploaded (20)

GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 

Crdt and their uses. SE 2016

  • 1. CRDT Data Structures And their real world uses
  • 2. Distributed counter (motivation example) Problem 20 20 +1 +1 21 21 21 21
  • 3. The problem Several active servers Semi-online systems (navigators, sales support software) Distributed systems (replication in general)
  • 4. Consistency … all nodes see the same data at the same time .. A A Consistency has costs
  • 5. Consistency Eventual consistency “ …. eventually all accesses to that item will return the last updated value … “ Strong eventual consistency “... any two nodes that have received the same (unordered) set of updates will be in the same state … “
  • 6. CRDT Conflict-free Replicated Data Type CvRDT (Convergent) aka 'state-based objects' CmRDT (Commutative) aka 'ops-based objects'
  • 7. First CRDT: G-Counter {a:4,b:5} {a:4,b:5} +1 +1 {a:5,b:5} {a:4,b:6} {a:5,b:6} {a:5,b:6} Value of the counter - sum of all parts
  • 8. CRDT counter: alternative 20 20 +1 +1 21 21 +1 +1 22 22
  • 9. G-Counter extension: PN-Counter What if decrement operation is also required? Use two g-counters: one for increments, another for decrements
  • 10. State based vs ops based State based: Merge should be: associative, commutative and idempotent (A ⨂ B) ⨂ C= A ⨂ (B ⨂ C) max(max(1, 2), 3) = max(1, max(2, 3)) A ⨂ B = B ⨂ A max(1, 2) = max(2, 1) A ⨂ B = A ⨂ B ⨂ B max(1, 2) = max(max(1, 2), 2)
  • 11. State based vs ops based Ops based: Replication channels should have exactly-once semantic and support causal ordering 21 21 +1 Concurrent operations should commute A B C D
  • 12. Example: Cassandra Cassandra’s distributed counters are implemented as PN-counters (almost) Cassandra’s general replication is implemented as another CRDT (LWW-Register) (data1,12) (data2,14) (data2,14) (data2,14)
  • 13. MV-Register (multi value) Vector clock Very similar to g-counter - {a:100, b: 98, c: 101} Each operation on server increments corresponding value Merge takes maximum of correlated elements One event is AFTER another if vector clock of one is less than vector clock of another: {a: 10, b: 11, c: 12} < {a:10, b:12, c:12}
  • 14. MV-Register Value is stored and replicated with vector clock On merge if one vector clock is bigger than another then keep value with bigger vector clock Otherwise keep both and let client choose which one to keep
  • 15. Example: Riak It uses MV-Register for general replication if multi-value mode is enabled It uses LWW-Register otherwise PN-counter is used to implement distributed counters Other CRDTs are also used (Sets, flags)
  • 16. G-Set (Grow only) Merge operation is set union, which is idempotent, commutative and associative Only add operation is supported
  • 17. OR-Set (observed remove) Idea is to use two sets for added and removed items, but... Store them with some unique id. Such id should be assigned during adding of element (a, id1) (a, id2) (b, id3) (c, id4) ‘Added’ Set (b, id3) ‘Removed’ Set (a, id2) Element is eligible to remove only if it is in ‘added’ set with same id
  • 18. Real life example: TomTom (navigators) Challenges: Account data (like favorites) can be modified from different devices concurrently Device can be offline during adding new information Huge number of accounts
  • 19. Real life example: TomTom (navigators) CRDT to rescue! They use combination of CRDT: MV-Register + modified OR-Set (OUR-Set) *Original image from TomTom’s presentation
  • 20. Real life example: Swarm.js Swarm is a reactive data sync library and middleware Swarm uses CRDT to merge data
  • 21. Real life example: Spark’s accumulator Docblock of Accumulable class A data type that can be accumulated, ie has an commutative and associative "add" operation You must define how to add data, and how to merge two of these together It seems like CRDT!
  • 22. Q/A