CSCE678 - CAP Theoremcourses.cse.tamu.edu/.../csce678/s19/slides/CAP-theorem.pdf · 2019-04-29 ·...

17
CAP Theorem CSCE678

Transcript of CSCE678 - CAP Theoremcourses.cse.tamu.edu/.../csce678/s19/slides/CAP-theorem.pdf · 2019-04-29 ·...

Page 1: CSCE678 - CAP Theoremcourses.cse.tamu.edu/.../csce678/s19/slides/CAP-theorem.pdf · 2019-04-29 · CAP Theorem •Trade-offs of three properties in a distributed system •Consistency:

CAP Theorem

CSCE678

Page 2: CSCE678 - CAP Theoremcourses.cse.tamu.edu/.../csce678/s19/slides/CAP-theorem.pdf · 2019-04-29 · CAP Theorem •Trade-offs of three properties in a distributed system •Consistency:

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

Page 3: CSCE678 - CAP Theoremcourses.cse.tamu.edu/.../csce678/s19/slides/CAP-theorem.pdf · 2019-04-29 · CAP Theorem •Trade-offs of three properties in a distributed system •Consistency:

Think about Amazon

3

I want to buy this book!

I want to buy this book!

Page 4: CSCE678 - CAP Theoremcourses.cse.tamu.edu/.../csce678/s19/slides/CAP-theorem.pdf · 2019-04-29 · CAP Theorem •Trade-offs of three properties in a distributed system •Consistency:

Consistency

• Each copy can only be sold once

4

Page 5: CSCE678 - CAP Theoremcourses.cse.tamu.edu/.../csce678/s19/slides/CAP-theorem.pdf · 2019-04-29 · CAP Theorem •Trade-offs of three properties in a distributed system •Consistency:

Availability

• If North America server failed, Singapore server can

still sell the book.

5

Page 6: CSCE678 - CAP Theoremcourses.cse.tamu.edu/.../csce678/s19/slides/CAP-theorem.pdf · 2019-04-29 · CAP Theorem •Trade-offs of three properties in a distributed system •Consistency:

Partition Tolerance

• If interconnection temporarily fails, the system can

still work (but with some trade-offs)

6

Page 7: CSCE678 - CAP Theoremcourses.cse.tamu.edu/.../csce678/s19/slides/CAP-theorem.pdf · 2019-04-29 · CAP Theorem •Trade-offs of three properties in a distributed system •Consistency:

Impossibility in CAP Theorem

• Any system cannot achieve all three properties

7

Availability

Consistency

PartitionTolerance

This can neverhappen

Page 8: CSCE678 - CAP Theoremcourses.cse.tamu.edu/.../csce678/s19/slides/CAP-theorem.pdf · 2019-04-29 · CAP Theorem •Trade-offs of three properties in a distributed system •Consistency:

Consistency + Partition Tolerance

• Requirement: only one book to sell, but may lose

interconnection

8

Page 9: CSCE678 - CAP Theoremcourses.cse.tamu.edu/.../csce678/s19/slides/CAP-theorem.pdf · 2019-04-29 · CAP Theorem •Trade-offs of three properties in a distributed system •Consistency:

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?

Page 10: CSCE678 - CAP Theoremcourses.cse.tamu.edu/.../csce678/s19/slides/CAP-theorem.pdf · 2019-04-29 · CAP Theorem •Trade-offs of three properties in a distributed system •Consistency:

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!

Page 11: CSCE678 - CAP Theoremcourses.cse.tamu.edu/.../csce678/s19/slides/CAP-theorem.pdf · 2019-04-29 · CAP Theorem •Trade-offs of three properties in a distributed system •Consistency:

Availability + Partition Tolerance

• Solution: distributed states

11

One book may be sold twice➔ No consistency

You got the book!

You got the book!

Page 12: CSCE678 - CAP Theoremcourses.cse.tamu.edu/.../csce678/s19/slides/CAP-theorem.pdf · 2019-04-29 · CAP Theorem •Trade-offs of three properties in a distributed system •Consistency:

Consistency + Availability

• Requirement: only one book to sell, and everyone gets answered immediately

12

I want the book!

I want the book!

Page 13: CSCE678 - CAP Theoremcourses.cse.tamu.edu/.../csce678/s19/slides/CAP-theorem.pdf · 2019-04-29 · CAP Theorem •Trade-offs of three properties in a distributed system •Consistency:

Consistency + Availability

• Solution: centralized server

13

I order the book first!

I order the book second!

Needs to stay inter-connected➔ no partition tolerance

Page 14: CSCE678 - CAP Theoremcourses.cse.tamu.edu/.../csce678/s19/slides/CAP-theorem.pdf · 2019-04-29 · CAP Theorem •Trade-offs of three properties in a distributed system •Consistency:

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

Page 15: CSCE678 - CAP Theoremcourses.cse.tamu.edu/.../csce678/s19/slides/CAP-theorem.pdf · 2019-04-29 · CAP Theorem •Trade-offs of three properties in a distributed system •Consistency:

Impossibility in CAP Theorem

15

Availability

Consistency

PartitionTolerance

Page 16: CSCE678 - CAP Theoremcourses.cse.tamu.edu/.../csce678/s19/slides/CAP-theorem.pdf · 2019-04-29 · CAP Theorem •Trade-offs of three properties in a distributed system •Consistency:

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

Page 17: CSCE678 - CAP Theoremcourses.cse.tamu.edu/.../csce678/s19/slides/CAP-theorem.pdf · 2019-04-29 · CAP Theorem •Trade-offs of three properties in a distributed system •Consistency:

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