eventual consitency with crdts

50
@YourTwitterHandle #Devoxx #YourTag @samklr #devoxx #CRDT Eventual Consistency without Consensus with CRDTs Sam BESSALAH - @samklr

Upload: samir-bessalah

Post on 13-Jan-2017

270 views

Category:

Software


0 download

TRANSCRIPT

Page 1: Eventual Consitency with CRDTS

@YourTwitterHandle#Devoxx #YourTag @samklr#devoxx #CRDT

Eventual Consistency without Consensus with CRDTs

Sam BESSALAH - @samklr

Page 2: Eventual Consitency with CRDTS

@YourTwitterHandle#Devoxx #YourTag @samklr#devoxx #CRDT

“ This talk is filled with words and terms, that might make you sound too nerdy or pedantic at dinners with non developers friends. ”

Use with caution.

Page 3: Eventual Consitency with CRDTS

@YourTwitterHandle#Devoxx #YourTag @samklr#devoxx #CRDT

“ Distributed Programming, generally a bad idea, best avoided. ”

-Peter Bourgon

Page 4: Eventual Consitency with CRDTS

@YourTwitterHandle#Devoxx #YourTag @samklr#devoxx #CRDT

Page 5: Eventual Consitency with CRDTS

@YourTwitterHandle#Devoxx #YourTag @samklr#devoxx #CRDT

Page 6: Eventual Consitency with CRDTS

@YourTwitterHandle#Devoxx #YourTag @samklr#devoxx #CRDT

- Availability- Fault tolerance- Throughtput- Architecture- Economics

Why we use distributed systems?

Page 7: Eventual Consitency with CRDTS

@YourTwitterHandle#Devoxx #YourTag @samklr#devoxx #CRDT

Page 8: Eventual Consitency with CRDTS

@YourTwitterHandle#Devoxx #YourTag @samklr#devoxx #CRDT

CAP Theorem

S. Gilbert and N. A. Lynch. Brewer’s conjecture and the feasibility of consistent, available, partition-tolerant web services. SIGACT News, 33(2):51–59, 2002.

Page 9: Eventual Consitency with CRDTS

@YourTwitterHandle#Devoxx #YourTag @samklr#devoxx #CRDT

http://bravenewgeek.com/from-mainframe-to-microservice-an-introduction-to-distributed-systems/

Page 10: Eventual Consitency with CRDTS

@YourTwitterHandle#Devoxx #YourTag @samklr#devoxx #CRDT

Data Consistency?

Consensus Systems ,

Locking Services and

“barbaric“ algorithms

Page 11: Eventual Consitency with CRDTS

@YourTwitterHandle#Devoxx #YourTag @samklr#devoxx #CRDT

Data Consistency?

- Distributed Consensus : Costly and nearly impossible. Multi Phase Commit, Stae Replication

- Two Phase Commit : Blocking, dependent on coordinator, deadlocks inducing

- Three Phase commit : abort on timeouts, non blocking but easily fails on network partitions

Page 12: Eventual Consitency with CRDTS

@YourTwitterHandle#Devoxx #YourTag @samklr#devoxx #CRDT

Data Consistency?

Page 13: Eventual Consitency with CRDTS

@YourTwitterHandle#Devoxx #YourTag @samklr#devoxx #CRDT

Data Consistency?

Page 14: Eventual Consitency with CRDTS

@YourTwitterHandle#Devoxx #YourTag @samklr#devoxx #CRDT

Data Consistency?

Page 15: Eventual Consitency with CRDTS

@YourTwitterHandle#Devoxx #YourTag @samklr#devoxx #CRDT

Data Consistency? RAFT

Page 16: Eventual Consitency with CRDTS

@YourTwitterHandle#Devoxx #YourTag @samklr#devoxx #CRDT

Data Consistency? Locking Services

Chubby (Google) Zab (Yahoo)

Page 17: Eventual Consitency with CRDTS

@YourTwitterHandle#Devoxx #YourTag @samklr#devoxx #CRDT

http://bravenewgeek.com/from-mainframe-to-microservice-an-introduction-to-distributed-systems/

Page 18: Eventual Consitency with CRDTS

@YourTwitterHandle#Devoxx #YourTag @samklr#devoxx #CRDT

@aphyr

Page 19: Eventual Consitency with CRDTS

@YourTwitterHandle#Devoxx #YourTag @samklr#devoxx #CRDT

“ Consistency is a property of your data, not of your nodes”

@aphyr

Page 20: Eventual Consitency with CRDTS

@YourTwitterHandle#Devoxx #YourTag @samklr#devoxx #CRDT

AP Systems Eventual Consistency

Page 21: Eventual Consitency with CRDTS

@YourTwitterHandle#Devoxx #YourTag @samklr#devoxx #CRDT

AP Systems Eventual Consistency

- High Availability- Low Latency- Fault tolerant

Page 22: Eventual Consitency with CRDTS

@YourTwitterHandle#Devoxx #YourTag @samklr#devoxx #CRDT

AP Systems Eventual Consistency

- High Availability- Low Latency- Fault tolerant

Page 23: Eventual Consitency with CRDTS

@YourTwitterHandle#Devoxx #YourTag @samklr#devoxx #CRDT

Dynamo Systems

Riak

Voldemort Cassandra

Page 24: Eventual Consitency with CRDTS

@YourTwitterHandle#Devoxx #YourTag @samklr#devoxx #CRDT

Page 25: Eventual Consitency with CRDTS

@YourTwitterHandle#Devoxx #YourTag @samklr#devoxx #CRDT

Conflicts resolution

- Semantic Resolution

- Vector Clocks

- Last write wins (LWW)

Page 26: Eventual Consitency with CRDTS

@YourTwitterHandle#Devoxx #YourTag @samklr#devoxx #CRDT

Vector Clocks LWW

Page 27: Eventual Consitency with CRDTS

@YourTwitterHandle#Devoxx #YourTag @samklr#devoxx #CRDT

Convergent Replicated Data Types

Page 28: Eventual Consitency with CRDTS

@YourTwitterHandle#Devoxx #YourTag @samklr#devoxx #CRDT

Page 29: Eventual Consitency with CRDTS

@YourTwitterHandle#Devoxx #YourTag @samklr#devoxx #CRDT

CRDTs- Take the consistency problem to the

level of Data Structures

- Their state resolves automatically (eventually) to a single coherent value

- Maintain multiple copies of your data

Page 30: Eventual Consitency with CRDTS

@YourTwitterHandle#Devoxx #YourTag @samklr#devoxx #CRDT

CRDTs : Monotonicity

- Every new operation adds information- Data is never immediately destroyed- Most things are trasparent to the

application

Page 31: Eventual Consitency with CRDTS

@YourTwitterHandle#Devoxx #YourTag @samklr#devoxx #CRDT

CRDTs : 2 types

- State based or convergent ( CvRDTs)

- Commutative or Operations based (CmRDTs)

*

Page 32: Eventual Consitency with CRDTS

@YourTwitterHandle#Devoxx #YourTag @samklr#devoxx #CRDT

CvRDTs

- All replicas connected - At least once semantics usually- State Changes advance upwards according to

partial order

Page 33: Eventual Consitency with CRDTS

@YourTwitterHandle#Devoxx #YourTag @samklr#devoxx #CRDT

CmRDTs

- All replicas connected - Need Reliable broadcast with ordering

guarantees- Best suitable for commutative updates

Page 34: Eventual Consitency with CRDTS

@YourTwitterHandle#Devoxx #YourTag @samklr#devoxx #CRDT

CRDTs : Fancy words

CRDTs are idempotent, commutative monoids !!!

Page 35: Eventual Consitency with CRDTS

@YourTwitterHandle#Devoxx #YourTag @samklr#devoxx #CRDT

CRDTs : Fancy words

CRDTs are idempotent, commutative monoid !!!

aka

Joint Semi Lattice

Page 36: Eventual Consitency with CRDTS

@YourTwitterHandle#Devoxx #YourTag @samklr#devoxx #CRDT

- Idempotence : A * A = A- Commutative : A*B = B* A- Associative : A*(B*C) = (A*B)*C

Joint SemiLattice

Page 37: Eventual Consitency with CRDTS

@YourTwitterHandle#Devoxx #YourTag @samklr#devoxx #CRDT

CvRDTs

Page 38: Eventual Consitency with CRDTS

@YourTwitterHandle#Devoxx #YourTag @samklr#devoxx #CRDT

Some common CRDTs

- Registers (LWW, Multi Valued Register)

- G-Counter

- PN Counter

- G-Set, 2P-Set and OR-Set

- Graph

- Maps

Page 39: Eventual Consitency with CRDTS

@YourTwitterHandle#Devoxx #YourTag @samklr#devoxx #CRDT

G- Counter : grow only counter

Page 40: Eventual Consitency with CRDTS

@YourTwitterHandle#Devoxx #YourTag @samklr#devoxx #CRDT

PN-Counter

- Positive and Negative Counters- Uses two G-counter- One for increments(P) and another for

decrement(N)- Result is the difference

Page 41: Eventual Consitency with CRDTS

@YourTwitterHandle#Devoxx #YourTag @samklr#devoxx #CRDT

G-Set

Grow only set, that only allows to add an element

Page 42: Eventual Consitency with CRDTS

@YourTwitterHandle#Devoxx #YourTag @samklr#devoxx #CRDT

2P-Set

- Two Phase Set- Built with 2 G-set for add and removal- Can’t add an already removed element :

Tombstone set- Has a tombstone that maintains

deleted elements

Page 43: Eventual Consitency with CRDTS

@YourTwitterHandle#Devoxx #YourTag @samklr#devoxx #CRDT

LWW-Element-set

- Add Timestamp to “add” and “remove” states wit h a timestamp.

- Greatest timestamps wins

- Close to cassandra model

Page 44: Eventual Consitency with CRDTS

@YourTwitterHandle#Devoxx #YourTag @samklr#devoxx #CRDT

CRDTs in the Wild

Page 45: Eventual Consitency with CRDTS

@YourTwitterHandle#Devoxx #YourTag @samklr#devoxx #CRDT

Page 46: Eventual Consitency with CRDTS

@YourTwitterHandle#Devoxx #YourTag @samklr#devoxx #CRDT

www.jepsen.io

- Riak- Cassandra- Kafka- etc.

Page 47: Eventual Consitency with CRDTS

@YourTwitterHandle#Devoxx #YourTag @samklr#devoxx #CRDT

Roshihttps://github.com/

soundcloud/roshi

Page 48: Eventual Consitency with CRDTS

@YourTwitterHandle#Devoxx #YourTag @samklr#devoxx #CRDT

Eventuate

Page 49: Eventual Consitency with CRDTS

@YourTwitterHandle#Devoxx #YourTag @samklr#devoxx #CRDT

Limitations

- Garbage Collection- Not always easy to have Semi

Lattice for all use case- Inducing some strange behaviours- Might require adding a stronger

consistency models: Raft, Paxos, etc- Use when availability is really

important- Don’t use them for your billing

application- Definitely not a panacea

Page 50: Eventual Consitency with CRDTS

@YourTwitterHandle#Devoxx #YourTag @samklr#devoxx #CRDT