Upload
others
View
3
Download
0
Embed Size (px)
Citation preview
CAP Theorem
CSCE678
CAP Theorem
• Trade-offs of three properties in a distributed system
• Consistency:
All nodes see the same states
• Availability:
If one node fails, other nodes can still operate
• Partition tolerance:
The system can be partitioned by network
2
By Eric Brewer in PODC 2000 Keynote
Think about Amazon
3
I want to buy this book!
I want to buy this book!
Consistency
• Each copy can only be sold once
4
Availability
• If North America server failed, Singapore server can
still sell the book.
5
Partition Tolerance
• If interconnection temporarily fails, the system can
still work (but with some trade-offs)
6
Impossibility in CAP Theorem
• Any system cannot achieve all three properties
7
Availability
Consistency
PartitionTolerance
This can neverhappen
Consistency + Partition Tolerance
• Requirement: only one book to sell, but may lose
interconnection
8
Consistency + Partition Tolerance
• Solution: fail and retry
9
One node may wait for another node forever➔ No availability
Can I have the book?
Can I have the book?
Availability + Partition Tolerance
• Requirement: everyone needs to get answered, even without interconnection.
10
Tell me if the book is available!
Tell me if the book is available!
Availability + Partition Tolerance
• Solution: distributed states
11
One book may be sold twice➔ No consistency
You got the book!
You got the book!
Consistency + Availability
• Requirement: only one book to sell, and everyone gets answered immediately
12
I want the book!
I want the book!
Consistency + Availability
• Solution: centralized server
13
I order the book first!
I order the book second!
Needs to stay inter-connected➔ no partition tolerance
Unfortunately, C + A Is Impossible
• Network failures happen all the time
• 50% chance the interval between inter-data-center network failures is less than 5 minutes
• 10% chance network repairment can take more than 1 hour or even 1 week
• In short, you cannot forgo partition tolerance
14
Source: Microsoft 2011 SIGCOMM paper
Impossibility in CAP Theorem
15
Availability
Consistency
PartitionTolerance
ACID Properties
A relational DB must have these properties:
• Atomicity: A transaction can only finish, or fail completely.
• Consistency: A transaction can only move DB from one valid state to another valid state.
• Isolation: Two concurrent transactions must have the same effect as running sequentially.
• Durability: Once a transaction finish, the result will remain.
➔ Requires C, A, and P to build a distributed DB
16
Trade-Off with Weaker Properties
• Weak consistency - Eventual consistency
• Distributed system state can diverge temporarily as long as it eventually converge
• Domain name server (DNS)
• Web caching – Content delivery network (CDN)
• ZooKeeper
• Weak availability
• Consensus with majority availability
• Distributed locking services – Google Chubby Locking
17