CAP Theorem CAP Theorem Assumed by Prof. Eric

Published  . 0 views
↓ Download
CAP Theorem CAP Theorem Assumed by Prof. Eric
1 / 1
CAP Theorem CAP Theorem Assumed by Prof. Eric - slide 1 of 64 CAP Theorem CAP Theorem Assumed by Prof. Eric - slide 2 of 64 CAP Theorem CAP Theorem Assumed by Prof. Eric - slide 3 of 64 CAP Theorem CAP Theorem Assumed by Prof. Eric - slide 4 of 64 CAP Theorem CAP Theorem Assumed by Prof. Eric - slide 5 of 64 CAP Theorem CAP Theorem Assumed by Prof. Eric - slide 6 of 64 CAP Theorem CAP Theorem Assumed by Prof. Eric - slide 7 of 64 CAP Theorem CAP Theorem Assumed by Prof. Eric - slide 8 of 64 CAP Theorem CAP Theorem Assumed by Prof. Eric - slide 9 of 64 CAP Theorem CAP Theorem Assumed by Prof. Eric - slide 10 of 64 CAP Theorem CAP Theorem Assumed by Prof. Eric - slide 11 of 64 CAP Theorem CAP Theorem Assumed by Prof. Eric - slide 12 of 64 CAP Theorem CAP Theorem Assumed by Prof. Eric - slide 13 of 64 CAP Theorem CAP Theorem Assumed by Prof. Eric - slide 14 of 64 CAP Theorem CAP Theorem Assumed by Prof. Eric - slide 15 of 64 CAP Theorem CAP Theorem Assumed by Prof. Eric - slide 16 of 64 CAP Theorem CAP Theorem Assumed by Prof. Eric - slide 17 of 64 CAP Theorem CAP Theorem Assumed by Prof. Eric - slide 18 of 64 CAP Theorem CAP Theorem Assumed by Prof. Eric - slide 19 of 64 CAP Theorem CAP Theorem Assumed by Prof. Eric - slide 20 of 64 CAP Theorem CAP Theorem Assumed by Prof. Eric - slide 21 of 64 CAP Theorem CAP Theorem Assumed by Prof. Eric - slide 22 of 64 CAP Theorem CAP Theorem Assumed by Prof. Eric - slide 23 of 64 CAP Theorem CAP Theorem Assumed by Prof. Eric - slide 24 of 64 CAP Theorem CAP Theorem Assumed by Prof. Eric - slide 25 of 64 CAP Theorem CAP Theorem Assumed by Prof. Eric - slide 26 of 64 CAP Theorem CAP Theorem Assumed by Prof. Eric - slide 27 of 64 CAP Theorem CAP Theorem Assumed by Prof. Eric - slide 28 of 64 CAP Theorem CAP Theorem Assumed by Prof. Eric - slide 29 of 64 CAP Theorem CAP Theorem Assumed by Prof. Eric - slide 30 of 64 CAP Theorem CAP Theorem Assumed by Prof. Eric - slide 31 of 64 CAP Theorem CAP Theorem Assumed by Prof. Eric - slide 32 of 64 CAP Theorem CAP Theorem Assumed by Prof. Eric - slide 33 of 64 CAP Theorem CAP Theorem Assumed by Prof. Eric - slide 34 of 64 CAP Theorem CAP Theorem Assumed by Prof. Eric - slide 35 of 64 CAP Theorem CAP Theorem Assumed by Prof. Eric - slide 36 of 64 CAP Theorem CAP Theorem Assumed by Prof. Eric - slide 37 of 64 CAP Theorem CAP Theorem Assumed by Prof. Eric - slide 38 of 64 CAP Theorem CAP Theorem Assumed by Prof. Eric - slide 39 of 64 CAP Theorem CAP Theorem Assumed by Prof. Eric - slide 40 of 64 CAP Theorem CAP Theorem Assumed by Prof. Eric - slide 41 of 64 CAP Theorem CAP Theorem Assumed by Prof. Eric - slide 42 of 64 CAP Theorem CAP Theorem Assumed by Prof. Eric - slide 43 of 64 CAP Theorem CAP Theorem Assumed by Prof. Eric - slide 44 of 64 CAP Theorem CAP Theorem Assumed by Prof. Eric - slide 45 of 64 CAP Theorem CAP Theorem Assumed by Prof. Eric - slide 46 of 64 CAP Theorem CAP Theorem Assumed by Prof. Eric - slide 47 of 64 CAP Theorem CAP Theorem Assumed by Prof. Eric - slide 48 of 64 CAP Theorem CAP Theorem Assumed by Prof. Eric - slide 49 of 64 CAP Theorem CAP Theorem Assumed by Prof. Eric - slide 50 of 64 CAP Theorem CAP Theorem Assumed by Prof. Eric - slide 51 of 64 CAP Theorem CAP Theorem Assumed by Prof. Eric - slide 52 of 64 CAP Theorem CAP Theorem Assumed by Prof. Eric - slide 53 of 64 CAP Theorem CAP Theorem Assumed by Prof. Eric - slide 54 of 64 CAP Theorem CAP Theorem Assumed by Prof. Eric - slide 55 of 64 CAP Theorem CAP Theorem Assumed by Prof. Eric - slide 56 of 64 CAP Theorem CAP Theorem Assumed by Prof. Eric - slide 57 of 64 CAP Theorem CAP Theorem Assumed by Prof. Eric - slide 58 of 64 CAP Theorem CAP Theorem Assumed by Prof. Eric - slide 59 of 64 CAP Theorem CAP Theorem Assumed by Prof. Eric - slide 60 of 64 CAP Theorem CAP Theorem Assumed by Prof. Eric - slide 61 of 64 CAP Theorem CAP Theorem Assumed by Prof. Eric - slide 62 of 64 CAP Theorem CAP Theorem Assumed by Prof. Eric - slide 63 of 64 CAP Theorem CAP Theorem Assumed by Prof. Eric - slide 64 of 64
Description: CAP Theorem CAP Theorem Assumed by Prof. Eric Brewer at PODC (Principle of Distributed Computing) 2000 keynote talk Described the trade-offs involved in distributed system It is impossible for a web service to provide following three

Related Topics

Download Presentation

"CAP Theorem CAP Theorem Assumed by Prof. Eric" is the property of its rightful owner. Permission is granted to download and print the materials on this website for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.

Presentation Transcript

slide1. CAP Theorem<br>
slide2. CAP Theorem Assumed by Prof. Eric Brewer at PODC (Principle of Distributed Computing) 2000 keynote talk

Described the trade-offs involved in distributed system

It is impossible for a web service to provide following three guarantees at the same time:
Consistency
Availability
Partition-tolerance<br>
slide3. CAP Theorem Consistency:
All nodes should see the same data at the same time
Availability:
Node failures do not prevent survivors from continuing to operate
Partition-tolerance:
The system continues to operate despite network partitions
A distributed system can satisfy any two of these guarantees at the same time but not all three<br>
slide4. CAP Theorem C A P<br>
slide5. CAP Theorem A simple example: Hotel Booking: are we double-booking the same room? Bob Dong<br>
slide6. CAP Theorem A simple example: Hotel Booking: are we double-booking the same room? Bob Dong<br>
slide7. CAP Theorem A simple example: Hotel Booking: are we double-booking the same room? Bob Dong<br>
slide8. CAP Theorem: Proof 2002: Proven by research conducted by Nancy Lynch and Seth Gilbert at MIT Gilbert, Seth, and Nancy Lynch. "Brewer's conjecture and the feasibility of consistent, available, partition-tolerant web services." ACM SIGACT News 33.2 (2002): 51-59.<br>
slide9. CAP Theorem: Proof A simple proof using two nodes: A B<br>
slide10. CAP Theorem: Proof A simple proof using two nodes: A B Not Consistent! Respond to client<br>
slide11. CAP Theorem: Proof A simple proof using two nodes: A B Not Available! Wait to be updated<br>
slide12. CAP Theorem: Proof A simple proof using two nodes: A B Not Partition Tolerant! A gets updated from B<br>
slide13. Why this is important? The future of databases is distributed (Big Data Trend, etc.)
CAP theorem describes the trade-offs involved in distributed systems
A proper understanding of CAP theorem is essential to making decisions about the future of distributed database design
Misunderstanding can lead to erroneous or inappropriate design choices<br>
slide14. Problem for Relational Database to Scale The Relational Database is built on the principle of ACID (Atomicity, Consistency, Isolation, Durability)
It implies that a truly distributed relational database should have availability, consistency and partition tolerance.
Which unfortunately is impossible …<br>
slide15. Revisit CAP Theorem Of the following three guarantees potentially offered a by distributed systems:
Consistency
Availability
Partition tolerance

Pick two

This suggests there are three kinds of distributed systems:
CP
AP
CA Any problems?<br>
slide16. A popular misconception: 2 out 3 How about CA?
Can a distributed system (with unreliable network) really be not tolerant of partitions? C A<br>
slide17. A few witnesses Coda Hale, Yammer software engineer:
“Of the CAP theorem’s Consistency, Availability, and Partition Tolerance, Partition Tolerance is mandatory in distributed systems. You cannot not choose it.” http://codahale.com/you-cant-sacrifice-partition-tolerance/<br>
slide18. A few witnesses Werner Vogels, Amazon CTO
“An important observation is that in larger distributed-scale systems, network partitions are a given; therefore, consistency and availability cannot be achieved at the same time.” http://www.allthingsdistributed.com/2008/12/eventually_consistent.html<br>
slide19. A few witnesses Daneil Abadi, Co-founder of Hadapt
So in reality, there are only two types of systems ... I.e., if there is a partition, does the system give up availability or consistency? http://dbmsmusings.blogspot.com/2010/04/problems-with-cap-and-yahoos-little.html<br>
slide20. CAP Theorem 12 year later Prof. Eric Brewer: father of CAP theorem
“The “2 of 3” formulation was always misleading because it tended to oversimplify the tensions among properties. ...
CAP prohibits only a tiny part of the design space: perfect availability and consistency in the presence of partitions, which are rare.” http://www.infoq.com/articles/cap-twelve-years-later-how-the-rules-have-changed<br>
slide21. Consistency or Availability Consistency and Availability is not “binary” decision

AP systems relax consistency in favor of availability – but are not inconsistent

CP systems sacrifice availability for consistency- but are not unavailable

This suggests both AP and CP systems can offer a degree of consistency, and availability, as well as partition tolerance<br>
slide22. AP: Best Effort Consistency Example:
Web Caching
DNS
Trait:
Optimistic
Expiration/Time-to-live
Conflict resolution<br>
slide23. CP: Best Effort Availability Example:
Majority protocols
Distributed Locking (Google Chubby Lock service)
Trait:
Pessimistic locking
Make minority partition unavailable<br>
slide24. Types of Consistency Strong Consistency
After the update completes, any subsequent access will return the same updated value.
Weak Consistency
It is not guaranteed that subsequent accesses will return the updated value.
Eventual Consistency
Specific form of weak consistency
It is guaranteed that if no new updates are made to object, eventually all accesses will return the last updated value (e.g., propagate updates to replicas in a lazy fashion)<br>
slide25. Eventual Consistency Variations Causal consistency
Processes that have causal relationship will see consistent data
Read-your-write consistency
A process always accesses the data item after it’s update operation and never sees an older value
Session consistency
As long as session exists, system guarantees read-your-write consistency<br>
slide26. Eventual Consistency Variations Monotonic read consistency
If a process has seen a value of data item, any subsequent processes will never return any previous values
Monotonic write consistency
The system guarantees to serialize the writes by the same process
In practice
A number of these properties can be combined
Monotonic reads and read-your-writes are most desirable<br>
slide27. Eventual Consistency - A Facebook Example Bob finds an interesting story and shares with Alice by posting on her Facebook wall
Bob asks Alice to check it out
Alice logs in her account, checks her Facebook wall but finds:
- Nothing is there! ?<br>
slide28. Eventual Consistency - A Facebook Example Bob tells Alice to wait a bit and check out later
Alice waits for a minute or so and checks back:
- She finds the story Bob shared with her!<br>
slide29. Eventual Consistency - A Facebook Example Reason: it is possible because Facebook uses an eventual consistent model
Why Facebook chooses eventual consistent model over the strong consistent one?
Facebook has more than 1 billion active users
It is non-trivial to efficiently and reliably store the huge amount of data generated at any given time
Eventual consistent model offers the option to reduce the load and improve availability<br>
slide30. Eventual Consistency - A Dropbox Example Dropbox enabled immediate consistency via synchronization in many cases.
However, what happens in case of a network partition?<br>
slide31. Eventual Consistency- A Dropbox Example Let’s do a simple experiment here:
Open a file in your drop box
Disable your network connection (e.g., WiFi, 4G)
Try to edit the file in the drop box: can you do that?
Re-enable your network connection: what happens to your dropbox folder?<br>
slide32. Eventual Consistency - A Dropbox Example Dropbox embraces eventual consistency:
Immediate consistency is impossible in case of a network partition
Users will feel bad if their word documents freeze each time they hit Ctrl+S , simply due to the large latency to update all devices across WAN
Dropbox is oriented to personal syncing, not on collaboration, so it is not a real limitation.<br>
slide33. Eventual Consistency- An ATM Example In design of automated teller machine (ATM):
Strong consistency appear to be a nature choice
However, in practice, A beats C
Higher availability means higher revenue
ATM will allow you to withdraw money even if the machine is partitioned from the network
However, it puts a limit on the amount of withdraw (e.g., $200)
The bank might also charge you a fee when a overdraft happens<br>
slide34. Dynamic Tradeoff between C and A An airline reservation system:
When most of seats are available: it is ok to rely on somewhat out-of-date data, availability is more critical
When the plane is close to be filled: it needs more accurate data to ensure the plane is not overbooked, consistency is more critical
Neither strong consistency nor guaranteed availability, but it may significantly increase the tolerance of network disruption<br>
slide35. Heterogeneity: Segmenting C and A No single uniform requirement
Some aspects require strong consistency
Others require high availability
Segment the system into different components
Each provides different types of guarantees
Overall guarantees neither consistency nor availability
Each part of the service gets exactly what it needs
Can be partitioned along different dimensions<br>
slide36. Discussion In an e-commercial system (e.g., Amazon, e-Bay, etc), what are the trade-offs between consistency and availability you can think of? What is your strategy?
Hint -> Things you might want to consider:
Different types of data (e.g., shopping cart, billing, product, etc.)
Different types of operations (e.g., query, purchase, etc.)
Different types of services (e.g., distributed lock, DNS, etc.)
Different groups of users (e.g., users in different geographic areas, etc.)<br>
slide37. Partitioning Examples Data Partitioning
Operational Partitioning
Functional Partitioning
User Partitioning
Hierarchical Partitioning<br>
slide38. Partitioning Examples Data Partitioning
Different data may require different consistency and availability
Example:
Shopping cart: high availability, responsive, can sometimes suffer anomalies
Product information need to be available, slight variation in inventory is sufferable
Checkout, billing, shipping records must be consistent<br>
slide39. Partitioning Examples Operational Partitioning
Each operation may require different balance between consistency and availability
Example:
Reads: high availability; e.g.., “query”
Writes: high consistency, lock when writing; e.g., “purchase”<br>
slide40. Partitioning Examples Functional Partitioning
System consists of sub-services
Different sub-services provide different balances
Example: A comprehensive distributed system
Distributed lock service (e.g., Chubby) :
Strong consistency
DNS service:
High availability<br>
slide41. Partitioning Examples User Partitioning
Try to keep related data close together to assure better performance
Example:
Might want to divide its service into several data centers, e.g., east coast and west coast
Users get high performance (e.g., high availability and good consistency) if they query servers closet to them
Poorer performance if a New York user query Craglist in San Francisco<br>
slide42. Partitioning Examples Hierarchical Partitioning
Large global service with local “extensions”
Different location in hierarchy may use different consistency
Example:
Local servers (better connected) guarantee more consistency and availability
Global servers has more partition and relax one of the requirement<br>
slide43. What if there are no partitions? Tradeoff between Consistency and Latency:
Caused by the possibility of failure in distributed systems
High availability -> replicate data -> consistency problem
Basic idea:
Availability and latency are arguably the same thing: unavailable -> extreme high latency
Achieving different levels of consistency/availability takes different amount of time<br>
slide44. CAP -> PACELC A more complete description of the space of potential tradeoffs for distributed system:
If there is a partition (P), how does the system trade off availability and consistency (A and C); else (E), when the system is running normally in the absence of partitions, how does the system trade off latency (L) and consistency (C)? Abadi, Daniel J. "Consistency tradeoffs in modern distributed database system design." Computer-IEEE Computer Magazine 45.2 (2012): 37.<br>
slide45. PACELC C A C L Partitioned Normal<br>
slide46. Examples PA/EL Systems: Give up both Cs for availability and lower latency
Dynamo, Cassandra, Riak
PC/EC Systems: Refuse to give up consistency and pay the cost of availability and latency
BigTable, Hbase, VoltDB/H-Store
PA/EC Systems: Give up consistency when a partition happens and keep consistency in normal operations
MongoDB
PC/EL System: Keep consistency if a partition occurs but gives up consistency for latency in normal operations
Yahoo! PNUTS<br>
slide47. Social Sensing & Cyber-Physical Systems Cyber
Physical
Systems Embedded Computing Systems Green Navigation Systems Zero-Energy Buildings Smart Grids Body Area Networks Social Sensing<br>
slide48. Proto Buffers<br>
slide49. Proto Buffers Transmit Data
Lots of Data
Robustly
Fast 49<br>
slide50. Options XML- May be 10 years ago
CSV- Sounds good
JSON- Looks promising
Proto Buffers – Thrift 50<br>
slide51. Formal Definition Protocol Buffers are Google's language neutral, platform-neutral, extensible mechanism for serializing structured data for use in communication protocols, data storage and many more. 51<br>
slide52. XML XML is smaller, faster and simpler
Data is transmitted in compact binary format
Data is transmitted in compact binary format 52<br>
slide53. How to Use Proto Buffers Define how you want your data to be structured in .proto file.
Generate data access classes using protocol buffer compiler
Write and read data from verity of data streams in your application
Specify transport mechanism 53<br>
slide54. Why Not XML or JSON PBs are simple to transfer
3 to 10 times smaller
20 to 100 times faster
Less ambiguous
Generate Data access classes that are easier to use programmatically 54<br>
slide55. File Format Representation XML
69 Bytes 55 <person>
<name> John Dee </name>
<email>jdoe@example.com</email>
</person> JSON
47 Bytes person{
Name=“John Dee”
Email:”jdoe@example.com”
} PB
28 Bytes Binary data 0s and 1s uses base 128 variants<br>
slide56. Sample .proto File message person{
require string name = 1;
required int32 id = 2;
optional string email= 3;
enum PhoneType{
MOBILE=0;
Home=1;
Work=2;
}
message PhoneNumber{
required string number =1;
optional PhoneType type = 2[Default = HOME]
}
repeated PhoneNUmber phone=4;
} 56<br>
slide57. Defining Message Types message Person{
require string name = 1;
required int32 id = 2;
optional string email= 3;
} Message Name Scalar Types Tags<br>
slide58. Field Rules Required- Message must have on of the field.
Optional – Message can have 0 or 1 field
Repeated – Message can have any number (including 0) in this field 58<br>
slide59. Defining a Service serive PersonService{
rpc getPersonByName(string) return Person;
} 59<br>
slide60. What is Generated from your .proto File Supports 3 languages
Java
C++
Python
For Java, the compiler generates a.java file with a class for each of message type. Special builder classes for creating message instance class
For C++ it generates .h and .cc files
For Python, a module with static descriptor for each message type. Which is used as metaclass to create a data access class at runtime 60<br>
slide61. Other Options Enumerations
Using other message Types(Instead of Scalar Types)
Nested Message
Comments
Extensions of Message 61<br>
slide62. Base 128 variants Methods of Serializing Integers
Smaller number take smaller number of Bytes
Each byte in a variant, except the last byte has the MSB set, to indicate further bytes to come
Lower 7bits of each byte store 2’s complement of the number in groups of bits, LSB first 62<br>
slide63. Encoding PB is series of key value pairs
Binary versions uses the field number as the key
The name and type is determined on the encoding end by looking at the .proto file
Key for each pair is two values – the field number from the .proto file and write type to find the length of the following values
(field_number << 3)write_type
Value is encoded using the Base invariant scheme 63<br>
slide64. Example message Test1{
required int32 a=1;
}

Set value of a = 150 in the application
Transmitted as 3 bytes 08 96 01 64<br>
slide65. Understanding the Example Message bytes 01 96 08
Encoding the key
Writetype of variant is 0. The tag of field is 1
Using (field<<3) write_type we get 000 1000 = 8
Decoding the value:
96 01 = 1001 0110 0000 0001
001 0110 0000 0001 (drop MSB)
000 0001 ++ 001 0110 (reverse the group of 7 bits)
10010110(conatenate)
128 + 16 + 4 + 2 = 150 65<br>