SlideShare a Scribd company logo
CAP Theorem &
Split Brain Syndrome
CS5242 Software Development on Cloud Platforms
Dilum Bandara, PhD
Slides adapted from
CSE 40822-Cloud Computing-Fall 2014 by Prof. Dong Wang
and
Reliable Distributed Systems by Ken Birman
CAP Theorem
• Conjectured 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 3 guarantees at the
same time:
• Consistency
• Availability
• Partition-tolerance 2
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:
– System continues to operate despite network
partitions
• A distributed system can satisfy any 2 of these
guarantees at the same time but not all 3
3
CAP Theorem
C A
P
4
CAP Theorem
• A simple example:
Hotel Booking: are we double-booking same room?
Bob Dong
5
CAP Theorem: Proof
• 2002: Proven by Nancy
Lynch & 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.
6
CAP Theorem: Proof
• A simple proof using 2 nodes:
A B
7
CAP Theorem: Proof
• A simple proof using 2 nodes:
A B
Not Consistent!
Respond to client 8
CAP Theorem: Proof
• A simple proof using 2 nodes:
A B
Not Partition
Tolerant!
A gets updated from B 9
Why this is important?
• Future of databases is distributed (Big Data
Trend, etc.)
• CAP theorem describes the trade-offs
involved in distributed systems
• Proper understanding of CAP theorem is
essential to making decisions about
distributed database/system design
• Misunderstanding can lead to erroneous or
inappropriate design choices
10
Problem for Relational Database to Scale
• RDMS is built on the principle of ACID
– Atomicity, Consistency, Isolation, Durability
• It implies that a truly distributed RDMSs
should have availability, consistency &
partition tolerance
• Which unfortunately is impossible …
11
Revisit CAP Theorem
C A
P
• Pick 2 out of 3 suggests there
are 3 kinds of distributed
systems:
• CP
• AP
• CA
Any problems?
12
A popular misconception: 2 out 3
• How about CA?
• Can a distributed system
(with unreliable network)
really be not tolerant of
partitions?
C A
13
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.”
• 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.”
• 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?
14
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 & consistency in the
presence of partitions, which are
rare.”
http://www.infoq.com/articles/cap-twelve-years-later-how-the-rules-have-changed15
Consistency or Availability
C A
P
• Consistency & 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 & CP
systems can offer a degree of
consistency, & availability, as
well as partition tolerance 16
AP: Best Effort Consistency
• Example:
– Web Caching
– DNS
• Trait:
– Optimistic
– Expiration/Time-to-live
– Conflict resolution
17
CP: Best Effort Availability
• Example:
– Majority protocols
– Distributed Locking (Google Chubby Lock service)
• Trait:
– Pessimistic locking
– Make minority partition unavailable
18
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)
19
Eventual Consistency
- A Dropbox Example
• Dropbox enabled immediate consistency via
synchronization in many cases.
• However, what happens in case of a network
partition?
20
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?
21
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.
22
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
23
Split brain Syndrome…
primary
backup
Clients initially connected to primary, which keeps
backup up to date. Backup collects the log
log
Split brain Syndrome…
Transient problem causes some links to break but not all.
Backup thinks it is now primary, primary thinks backup is down
primary
backup
Split brain Syndrome
Some clients still connected to primary, but one has switched
to backup and one is completely disconnected from both
primary
backup
Implication?
• Air Traffic System with a split brain could
malfunction disastrously!
– For example, suppose the service is used to
answer the question “is anyone flying in such-and-
such a sector of the sky”
– With the split-brain version, each half might say
“nope”… in response to different queries!
Can we fix this problem?
• No, if we insist on an end-to-end solution
– Essential insight is that we need some form of
“agreement” on which machines are up and which have
crashed
– Can’t implement “agreement” on a purely 1-to-1 (hence,
end-to-end) basis.
• Separate decisions can always lead to inconsistency
• So we need a “membership service”… and this is fundamentally
not an end-to-end concept!
Can we fix this problem?
• Yes, many options, once we accept this
– Just use a single server and wait for it to restart
• This common today, but too slow for ATC
– Give backup a way to physically “kill” the primary, e.g.
unplug it
• If backup takes over… primary shuts down
– Or require some form of “majority vote”
• Ad mentioned, maintains agreement on system status
• Bottom line? You need to anticipate the issue… and
to implement a solution.

More Related Content

PPTX
Blockchain basics
PDF
RethinkConn 2022!
PPTX
Blockchain Basics
PPTX
Presentation on DSL & ADSL
PPTX
Blockchain 2.0
PPTX
Unit 1
PDF
Blockchain Explained | Blockchain Simplified | Blockchain Technology | Blockc...
PDF
Open Source DataViz with Apache Superset
Blockchain basics
RethinkConn 2022!
Blockchain Basics
Presentation on DSL & ADSL
Blockchain 2.0
Unit 1
Blockchain Explained | Blockchain Simplified | Blockchain Technology | Blockc...
Open Source DataViz with Apache Superset

What's hot (20)

PPTX
Block chain technology and its applications
PDF
Blockchain
PDF
Cloud Computing paradigm
PPT
Virtualization.ppt
PPTX
Introduction to Bitcoin's Scripting Language
PPTX
Building Event Driven Architectures with Kafka and Cloud Events (Dan Rosanova...
PPTX
Client Server Architecture ppt
PDF
Understanding Blockchain: Distributed Ledger Technology
PPTX
Cloud operating system
PPT
Design principles of scalable, distributed systems
PDF
Blockchain 101 | Blockchain Tutorial | Blockchain Smart Contracts | Blockchai...
PPTX
Virtualization Vs. Containers
PPTX
01 - Introduction to Distributed Systems
PPTX
Block Chain
PPT
Cloud computing
PDF
Centralize and Simplify Secrets Management for Red Hat OpenShift Container En...
PDF
On Premise vs Cloud - Know The Difference and Benefits
PPTX
Introduction to Blockchain
PPTX
Distributed file system
Block chain technology and its applications
Blockchain
Cloud Computing paradigm
Virtualization.ppt
Introduction to Bitcoin's Scripting Language
Building Event Driven Architectures with Kafka and Cloud Events (Dan Rosanova...
Client Server Architecture ppt
Understanding Blockchain: Distributed Ledger Technology
Cloud operating system
Design principles of scalable, distributed systems
Blockchain 101 | Blockchain Tutorial | Blockchain Smart Contracts | Blockchai...
Virtualization Vs. Containers
01 - Introduction to Distributed Systems
Block Chain
Cloud computing
Centralize and Simplify Secrets Management for Red Hat OpenShift Container En...
On Premise vs Cloud - Know The Difference and Benefits
Introduction to Blockchain
Distributed file system
Ad

Similar to CAP Theorem and Split Brain Syndrome (20)

PPTX
cse40822-CAP.pptx
PPTX
CAP Theorem
PPTX
CAP Theorem - Theory, Implications and Practices
PDF
A Critique of the CAP Theorem by Martin Kleppmann
PDF
CM2-Data model for Big Data chapter2.pdf
PDF
Cap in depth
PPTX
Put Your Thinking CAP On
PPTX
Distributed System explained (with Java Microservices)
PPTX
All you didn't know about the CAP theorem
PPTX
U1-T9,T5-Distributed Vs Parallel Processing and Typical Hadoop Environment.pptx
PDF
Thoughts on consistency models
PDF
System design fundamentals CAP.pdf
PDF
Open west 2015 talk ben coverston
PPTX
Data Engineering for Data Scientists
PPTX
Prisoner's Dilemma and Service-oriented Architectures
PDF
Distributed Systems explained (with NodeJS) - Bruno Bossola, JUG Torino
PDF
Database Consistency Models
PDF
Petabytes and Nanoseconds
PDF
From Mainframe to Microservice: An Introduction to Distributed Systems
PPTX
Dynamo and BigTable in light of the CAP theorem
cse40822-CAP.pptx
CAP Theorem
CAP Theorem - Theory, Implications and Practices
A Critique of the CAP Theorem by Martin Kleppmann
CM2-Data model for Big Data chapter2.pdf
Cap in depth
Put Your Thinking CAP On
Distributed System explained (with Java Microservices)
All you didn't know about the CAP theorem
U1-T9,T5-Distributed Vs Parallel Processing and Typical Hadoop Environment.pptx
Thoughts on consistency models
System design fundamentals CAP.pdf
Open west 2015 talk ben coverston
Data Engineering for Data Scientists
Prisoner's Dilemma and Service-oriented Architectures
Distributed Systems explained (with NodeJS) - Bruno Bossola, JUG Torino
Database Consistency Models
Petabytes and Nanoseconds
From Mainframe to Microservice: An Introduction to Distributed Systems
Dynamo and BigTable in light of the CAP theorem
Ad

More from Dilum Bandara (20)

PPTX
Designing for Multiple Blockchains in Industry Ecosystems
PPTX
Introduction to Machine Learning
PPTX
Time Series Analysis and Forecasting in Practice
PPTX
Introduction to Dimension Reduction with PCA
PPTX
Introduction to Descriptive & Predictive Analytics
PPTX
Introduction to Concurrent Data Structures
PPTX
Hard to Paralelize Problems: Matrix-Vector and Matrix-Matrix
PPTX
Introduction to Map-Reduce Programming with Hadoop
PPTX
Embarrassingly/Delightfully Parallel Problems
PPTX
Introduction to Warehouse-Scale Computers
PPTX
Introduction to Thread Level Parallelism
PPTX
CPU Memory Hierarchy and Caching Techniques
PPTX
Data-Level Parallelism in Microprocessors
PDF
Instruction Level Parallelism – Hardware Techniques
PPTX
Instruction Level Parallelism – Compiler Techniques
PPTX
CPU Pipelining and Hazards - An Introduction
PPTX
Advanced Computer Architecture – An Introduction
PPTX
High Performance Networking with Advanced TCP
PPTX
Introduction to Content Delivery Networks
PPTX
Peer-to-Peer Networking Systems and Streaming
Designing for Multiple Blockchains in Industry Ecosystems
Introduction to Machine Learning
Time Series Analysis and Forecasting in Practice
Introduction to Dimension Reduction with PCA
Introduction to Descriptive & Predictive Analytics
Introduction to Concurrent Data Structures
Hard to Paralelize Problems: Matrix-Vector and Matrix-Matrix
Introduction to Map-Reduce Programming with Hadoop
Embarrassingly/Delightfully Parallel Problems
Introduction to Warehouse-Scale Computers
Introduction to Thread Level Parallelism
CPU Memory Hierarchy and Caching Techniques
Data-Level Parallelism in Microprocessors
Instruction Level Parallelism – Hardware Techniques
Instruction Level Parallelism – Compiler Techniques
CPU Pipelining and Hazards - An Introduction
Advanced Computer Architecture – An Introduction
High Performance Networking with Advanced TCP
Introduction to Content Delivery Networks
Peer-to-Peer Networking Systems and Streaming

Recently uploaded (20)

PDF
PPT on Performance Review to get promotions
PPTX
UNIT 4 Total Quality Management .pptx
PDF
Soil Improvement Techniques Note - Rabbi
PDF
BIO-INSPIRED ARCHITECTURE FOR PARSIMONIOUS CONVERSATIONAL INTELLIGENCE : THE ...
PDF
Exploratory_Data_Analysis_Fundamentals.pdf
PPT
introduction to datamining and warehousing
PPTX
6ME3A-Unit-II-Sensors and Actuators_Handouts.pptx
PPTX
communication and presentation skills 01
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PPTX
Artificial Intelligence
PDF
Artificial Superintelligence (ASI) Alliance Vision Paper.pdf
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PDF
Visual Aids for Exploratory Data Analysis.pdf
PDF
86236642-Electric-Loco-Shed.pdf jfkduklg
PPT
A5_DistSysCh1.ppt_INTRODUCTION TO DISTRIBUTED SYSTEMS
PDF
Abrasive, erosive and cavitation wear.pdf
PPT
INTRODUCTION -Data Warehousing and Mining-M.Tech- VTU.ppt
PDF
PREDICTION OF DIABETES FROM ELECTRONIC HEALTH RECORDS
PDF
R24 SURVEYING LAB MANUAL for civil enggi
PDF
Automation-in-Manufacturing-Chapter-Introduction.pdf
PPT on Performance Review to get promotions
UNIT 4 Total Quality Management .pptx
Soil Improvement Techniques Note - Rabbi
BIO-INSPIRED ARCHITECTURE FOR PARSIMONIOUS CONVERSATIONAL INTELLIGENCE : THE ...
Exploratory_Data_Analysis_Fundamentals.pdf
introduction to datamining and warehousing
6ME3A-Unit-II-Sensors and Actuators_Handouts.pptx
communication and presentation skills 01
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
Artificial Intelligence
Artificial Superintelligence (ASI) Alliance Vision Paper.pdf
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
Visual Aids for Exploratory Data Analysis.pdf
86236642-Electric-Loco-Shed.pdf jfkduklg
A5_DistSysCh1.ppt_INTRODUCTION TO DISTRIBUTED SYSTEMS
Abrasive, erosive and cavitation wear.pdf
INTRODUCTION -Data Warehousing and Mining-M.Tech- VTU.ppt
PREDICTION OF DIABETES FROM ELECTRONIC HEALTH RECORDS
R24 SURVEYING LAB MANUAL for civil enggi
Automation-in-Manufacturing-Chapter-Introduction.pdf

CAP Theorem and Split Brain Syndrome

  • 1. CAP Theorem & Split Brain Syndrome CS5242 Software Development on Cloud Platforms Dilum Bandara, PhD Slides adapted from CSE 40822-Cloud Computing-Fall 2014 by Prof. Dong Wang and Reliable Distributed Systems by Ken Birman
  • 2. CAP Theorem • Conjectured 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 3 guarantees at the same time: • Consistency • Availability • Partition-tolerance 2
  • 3. 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: – System continues to operate despite network partitions • A distributed system can satisfy any 2 of these guarantees at the same time but not all 3 3
  • 5. CAP Theorem • A simple example: Hotel Booking: are we double-booking same room? Bob Dong 5
  • 6. CAP Theorem: Proof • 2002: Proven by Nancy Lynch & 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. 6
  • 7. CAP Theorem: Proof • A simple proof using 2 nodes: A B 7
  • 8. CAP Theorem: Proof • A simple proof using 2 nodes: A B Not Consistent! Respond to client 8
  • 9. CAP Theorem: Proof • A simple proof using 2 nodes: A B Not Partition Tolerant! A gets updated from B 9
  • 10. Why this is important? • Future of databases is distributed (Big Data Trend, etc.) • CAP theorem describes the trade-offs involved in distributed systems • Proper understanding of CAP theorem is essential to making decisions about distributed database/system design • Misunderstanding can lead to erroneous or inappropriate design choices 10
  • 11. Problem for Relational Database to Scale • RDMS is built on the principle of ACID – Atomicity, Consistency, Isolation, Durability • It implies that a truly distributed RDMSs should have availability, consistency & partition tolerance • Which unfortunately is impossible … 11
  • 12. Revisit CAP Theorem C A P • Pick 2 out of 3 suggests there are 3 kinds of distributed systems: • CP • AP • CA Any problems? 12
  • 13. A popular misconception: 2 out 3 • How about CA? • Can a distributed system (with unreliable network) really be not tolerant of partitions? C A 13
  • 14. 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.” • 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.” • 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? 14
  • 15. 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 & consistency in the presence of partitions, which are rare.” http://www.infoq.com/articles/cap-twelve-years-later-how-the-rules-have-changed15
  • 16. Consistency or Availability C A P • Consistency & 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 & CP systems can offer a degree of consistency, & availability, as well as partition tolerance 16
  • 17. AP: Best Effort Consistency • Example: – Web Caching – DNS • Trait: – Optimistic – Expiration/Time-to-live – Conflict resolution 17
  • 18. CP: Best Effort Availability • Example: – Majority protocols – Distributed Locking (Google Chubby Lock service) • Trait: – Pessimistic locking – Make minority partition unavailable 18
  • 19. 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) 19
  • 20. Eventual Consistency - A Dropbox Example • Dropbox enabled immediate consistency via synchronization in many cases. • However, what happens in case of a network partition? 20
  • 21. 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? 21
  • 22. 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. 22
  • 23. 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 23
  • 24. Split brain Syndrome… primary backup Clients initially connected to primary, which keeps backup up to date. Backup collects the log log
  • 25. Split brain Syndrome… Transient problem causes some links to break but not all. Backup thinks it is now primary, primary thinks backup is down primary backup
  • 26. Split brain Syndrome Some clients still connected to primary, but one has switched to backup and one is completely disconnected from both primary backup
  • 27. Implication? • Air Traffic System with a split brain could malfunction disastrously! – For example, suppose the service is used to answer the question “is anyone flying in such-and- such a sector of the sky” – With the split-brain version, each half might say “nope”… in response to different queries!
  • 28. Can we fix this problem? • No, if we insist on an end-to-end solution – Essential insight is that we need some form of “agreement” on which machines are up and which have crashed – Can’t implement “agreement” on a purely 1-to-1 (hence, end-to-end) basis. • Separate decisions can always lead to inconsistency • So we need a “membership service”… and this is fundamentally not an end-to-end concept!
  • 29. Can we fix this problem? • Yes, many options, once we accept this – Just use a single server and wait for it to restart • This common today, but too slow for ATC – Give backup a way to physically “kill” the primary, e.g. unplug it • If backup takes over… primary shuts down – Or require some form of “majority vote” • Ad mentioned, maintains agreement on system status • Bottom line? You need to anticipate the issue… and to implement a solution.

Editor's Notes

  • #12: Atomicity requires that each transaction be "all or nothing" The consistency property ensures that any transaction will bring the database from one valid state to another. The isolation property ensures that the concurrent execution of transactions results in a system state that would be obtained if transactions were executed serially, The durability property ensures that once a transaction has been committed, it will remain so, even in the event of power loss, crashes, or errors.