Slide 1

Slide 1 text

CAP and PACELC : the basic theorem of distributed database system 181024 Copyright ⓒ All Right Reserved by Buzzvil Howard Kim Software Engineer

Slide 2

Slide 2 text

Copyright ⓒ All Right Reserved by Buzzvil Contents 1. What is CAP theorem? 2. Understanding CAP theorem 3. Limit of CAP 4. PACELC 5. Some examples 6. Conclusion

Slide 3

Slide 3 text

Copyright ⓒ All Right Reserved by Buzzvil Referenece - You don’t need CP, you don’t want AP, and you can’t have CA - Siddhartha Reddy

Slide 4

Slide 4 text

Copyright ⓒ All Right Reserved by Buzzvil What is CAP theorem? - “It is impossible for a distributed data store to simultaneously provide more than two out of the following three guarantees” - Eric Brewer, University of California, Berkeley (2000) - Seth Gilbert and Nancy Lynch of MIT (2002) - the Basic theorem in DDBS(distributed database system)

Slide 5

Slide 5 text

Copyright ⓒ All Right Reserved by Buzzvil What is CAP theorem?

Slide 6

Slide 6 text

Copyright ⓒ All Right Reserved by Buzzvil C : Consistency Node1 Node2 Read(A) 1 ?? Client 1 Client 2 - Every read receives the most recent write or an error Read(A)

Slide 7

Slide 7 text

Copyright ⓒ All Right Reserved by Buzzvil A : Availability Node Write (A, 2) Done Client Error / Fail - Every request receives a response that is not an error

Slide 8

Slide 8 text

Copyright ⓒ All Right Reserved by Buzzvil P : Partition tolerance - The system continues to operate despite an arbitrary number of messages being dropped (or delayed) by the network between nodes Node1 Node2 → Not P is Possible?

Slide 9

Slide 9 text

Copyright ⓒ All Right Reserved by Buzzvil Why CA (not P) is impossible? - 100% guaranteed network (never fails) → Impossible - even ONE BIG single Node can fail → Power failure, Equipment failure, Software bugs… → actually it is not distributed system So, Partition is a Reality. We can’t have CA.

Slide 10

Slide 10 text

Copyright ⓒ All Right Reserved by Buzzvil What is CAP theorem?

Slide 11

Slide 11 text

Copyright ⓒ All Right Reserved by Buzzvil Understanding CAP Node1 {A:1} Node2 {A:1} Write (A, 2) Client 1 Client 2 Inconsistent

Slide 12

Slide 12 text

Copyright ⓒ All Right Reserved by Buzzvil Understanding CAP Node1 {A:2} Node2 {A:1} Done Client 1 Client 2 Inconsistent

Slide 13

Slide 13 text

Copyright ⓒ All Right Reserved by Buzzvil Node1 {A:2} Node2 {A:1} Read(A) Client 1 Client 2 Inconsistent Understanding CAP

Slide 14

Slide 14 text

Copyright ⓒ All Right Reserved by Buzzvil Node1 {A:2} Node2 {A:1} 1 Client 1 Client 2 Inconsistent Inconsistent Understanding CAP

Slide 15

Slide 15 text

Copyright ⓒ All Right Reserved by Buzzvil Node1 {A:1} Node2 {A:1} Write (A, 2) Client 1 Client 2 Consistent Understanding CAP

Slide 16

Slide 16 text

Copyright ⓒ All Right Reserved by Buzzvil Node1 {A:2} Node2 {A:1} Client 1 Client 2 Write (A, 2) Consistent Understanding CAP

Slide 17

Slide 17 text

Copyright ⓒ All Right Reserved by Buzzvil Node1 {A:2} Node2 {A:2} Client 1 Client 2 Done Consistent Understanding CAP

Slide 18

Slide 18 text

Copyright ⓒ All Right Reserved by Buzzvil Node1 {A:2} Node2 {A:2} Done Client 1 Client 2 Consistent Understanding CAP

Slide 19

Slide 19 text

Copyright ⓒ All Right Reserved by Buzzvil Node1 {A:2} Node2 {A:2} Read(A) Client 1 Client 2 Consistent Understanding CAP

Slide 20

Slide 20 text

Copyright ⓒ All Right Reserved by Buzzvil Node1 {A:2} Node2 {A:2} 2 Client 1 Client 2 Cool Consistent Understanding CAP

Slide 21

Slide 21 text

Copyright ⓒ All Right Reserved by Buzzvil Node1 {A:1} Node2 {A:1} Write (A, 2) Client 1 Client 2 Partition condition Understanding CAP

Slide 22

Slide 22 text

Copyright ⓒ All Right Reserved by Buzzvil Node1 {A:2} Node2 {A:1} Client 1 Client 2 Consistent Have to make a choice Understanding CAP

Slide 23

Slide 23 text

Copyright ⓒ All Right Reserved by Buzzvil Node1 {A:2} Node2 {A:1} Client 1 Client 2 Consistent Node1 {A:1} Node2 {A:1} Client 1 Client 2 Error Node1 {A:2} Node2 {A:1} Client 1 Client 2 Done Understanding CAP

Slide 24

Slide 24 text

Copyright ⓒ All Right Reserved by Buzzvil Node1 {A:2} Node2 {A:1} Client 1 Client 2 Consistent Node1 {A:1} Node2 {A:1} Client 1 Client 2 Error Node1 {A:2} Node2 {A:1} Client 1 Client 2 Done CP AP Understanding CAP

Slide 25

Slide 25 text

Copyright ⓒ All Right Reserved by Buzzvil Perfect CP (sacrifice Availability)

Slide 26

Slide 26 text

Copyright ⓒ All Right Reserved by Buzzvil Perfect CP (sacrifice Availability) Always consistent in all nodes - Cost is very high : have to check all nodes in every request. - Risk grows rapidly when the number of nodes grows So, We don’t need Perfect CP.

Slide 27

Slide 27 text

Copyright ⓒ All Right Reserved by Buzzvil Perfect AP (sacrifice Consistency)

Slide 28

Slide 28 text

Copyright ⓒ All Right Reserved by Buzzvil Perfect AP (sacrifice Consistency) Always process request and response with OK. - Meaningless response : almost same with empty response - A unlucky client can't notice something is wrong So, We don’t want Perfect AP.

Slide 29

Slide 29 text

Copyright ⓒ All Right Reserved by Buzzvil Some point in spectrum Perfect CP Perfect AP Your System !

Slide 30

Slide 30 text

Copyright ⓒ All Right Reserved by Buzzvil Limit of CAP - CAP theorem is all about partition condition. - Partition is inevitable. But We are not always in partition condition So, We need another axis. → PACELC

Slide 31

Slide 31 text

Copyright ⓒ All Right Reserved by Buzzvil From CAP to PACELC - “... PACELC(pass-elk) however goes further and states that another trade-off also exists: this time between latency and consistency, even in absence of partitions ...” - Daniel J. Abadi from Yale University (2012)

Slide 32

Slide 32 text

Copyright ⓒ All Right Reserved by Buzzvil What is PACELC? If Partition exists Availability / Consistency Else Latency / Consistency

Slide 33

Slide 33 text

Copyright ⓒ All Right Reserved by Buzzvil Expansion to 2-dimension Consistency Availability Your System ! Consistency Latency Partition condition Normal condition

Slide 34

Slide 34 text

Copyright ⓒ All Right Reserved by Buzzvil Example of MySQL - Master-Slave Replication - Partition condition: sacrifice Consistency for Availability - Else: sacrifice Consistency for Latency (Async Replica)

Slide 35

Slide 35 text

Copyright ⓒ All Right Reserved by Buzzvil Example of MySQL - Master-Slave Replication - Partition condition: sacrifice Consistency for Availability - Else: sacrifice Consistency for Latency (Async Replica) sacrifice Latency for Consistency (Semi-sync)

Slide 36

Slide 36 text

Copyright ⓒ All Right Reserved by Buzzvil Example of MySQL Consistency Availability Consistency Latency Async Replication Semi-sync Replication

Slide 37

Slide 37 text

Copyright ⓒ All Right Reserved by Buzzvil Other DBs - DynamoDB, Cassandra : PA/EL (default version) - Mongo DB : PA/EC (baseline) - Volt DB/HBase: PC/EC

Slide 38

Slide 38 text

Copyright ⓒ All Right Reserved by Buzzvil Example of MySQL Consistency Availability Consistency Latency Async Replication Semi-sync Replication

Slide 39

Slide 39 text

Copyright ⓒ All Right Reserved by Buzzvil Conclusion - PACELC is a good tool(frame) for decision making about distributed database system. - Configuration can move the position of DB in PACELC quadrant. - There can be many things that PACELC is missing (e.g. quantity of data, shape of data etc) - Your Business logic matters: Banking vs SNS

Slide 40

Slide 40 text

Copyright ⓒ All Right Reserved by Buzzvil Referneces - You don’t need CP, you don’t want AP, and you can’t have CA - Siddhartha Reddy - https://speakerdeck.com/sids/cap-theorem-you-dont-need-cp-y ou-dont-want-ap-and-you-cant-have-ca - http://happinessoncode.com/2017/07/29/cap-theorem-and-pac elc-theorem/ - https://en.wikipedia.org/wiki/CAP_theorem - https://en.wikipedia.org/wiki/PACELC_theorem - http://cs-www.cs.yale.edu/homes/dna/papers/abadi-pacelc.pdf