SlideShare una empresa de Scribd logo
1 de 48
Descargar para leer sin conexión
MySQL and the CAP theorem:
relevance & misconceptions
Dissecting,affirmingandrefutingCAPassumptionsin
realproductionsystems.
ShlomiNoach
GitHub
FOSDEM2019
About me
@github/database-infrastructure
Authoroforchestrator,gh-ost,freno,ccql
andothers.
Blogathttp://openark.org


github.com/shlomi-noach

@ShlomiNoach
GitHub

Built for developers
Largestopensourcehosting
100M+repositories,31M+developers,

2.1M+organizations
SupplierofoctocatT-Shirtsandstickers
Incentive
Incentive
PeoplefrequentlyciteCAPtheorembywayof:
• Modellingasystem(asAP/CP).
• Projectingthatitisimpossibletoachievesomedesired
setup.
CAP Conjecture
SuggestedbyEricBrewer,1998-1999
Terms:
• [atomic]Consistency
• [high]Availability
• Partitiontolerance
CAP Theorem
Mathematicallyproved(hence“theorem”)bySethGilbert&
NancyLynch,MIT.
UsingdifferenttermsthanthosecoinedbyBrewer.
InMath,atheoremonlyholdsaslongasitsterms&conditions
aremet.
CAP Theorem
Terms,accordingtoGilbert&Lynch:
-Consistency
-Availability
-Partitiontolerance
CAP Theorem: Consistency
Onceawriteissuccessfulonanode,anyreadonanynodemust
reflectthatwriteoranylaterwrite.
akaAtomicConsistency,akaLinearconsistency,aka
Linearizability.
CAP Theorem: Availability
Everynon-crashednodemustrespondtorequestsinafinite
amountoftime.
Thereisnoconstraintontheactualamountoftime.
Thoughitisnotspecified,itisimpliedthatresponsemustbe
valid,non-error.
ContrastwithBrewer’sdefinitonofHighavailability: consumer
alwayshasaccesstodataviaatleastonereplica.
CAP Theorem: Partition Tolerance
Thesystemisabletooperateonnetworkpartitioning.
Partitiontoleranceisconsideredasagivencondition,since
networkpartitioningcananddoestakeplaceregardlessofa
system’sdesign.
CAP Theorem
Adistributeddatastore[webservice]cannotprovidemorethan
twooutofthethreeproperties.Betterillustratedas:
• Ifthenetworkisgood,youmayachievebothAvailibilityand
Consistency.
• Ifthenetworkispartitioned,youmustchoosebetween
AvailabilityandConsistency.
Proof of CAP theorem
Simplified,notbymuch.
Giventwonodesreplicatingfromeachother
! !
n1 n2
Proof of CAP theorem
Wepartitionthenetworkbetweenthetwonodestoaninfinite
amountoftime.
! !
n1 n2
Proof of CAP theorem
Wewritedatatoonenode.IfthesystemisAvailable,thewrite
compeltesinafiniteamountoftime.
! !
n1 n2
Proof of CAP theorem
Wereaddatafromtheothernode.IfthesystemisAvailable
thatreadcompletesinafinitemountoftime.
! !
n1 n2
Proof of CAP theorem
Duringthatfinitetimethenetworkwaspartitioned,henceour
readcouldnotreflectchangesmadebythewrite.
QED
! !
n1 n2
CAP is mathematical
Asengineerswehavedifferentproductionobjectives.
CAP is binary
Thetheoremhasnothingtosayof99.95%Availabilitywith
99.99%Consistency
Tradeoffsandpartialavailability&consistencyarediscussedin
bothBrewer’sConjecturepaperandGilbert&Lynch’sTheorem
paper,buthavenopartintheproof.
CAP does not discuss
DisasterRecovery
Failover
Latency(seePACELC)
Durability,noderecovery
SLA,uptime,nines
Scalability,capacity
CAP & MySQL in production
Standard MySQL replication
Singlemaster,multiplereplicas,asynchronousreplication
! !
!
!
!
!
Standard MySQL replication:

CAP properties
NotConsistent:asynchronousreplication,replicationlag.
NotAvailable:
• Replicanodesareunabletoservewrites(returnwitherror).
• Ifmastercrashes,noservertobeabletotakewrites.
• CAPdoesnotdiscussfailovers/SLA.
! !
!
!
!
!
Standard MySQL replication:

consistency in practice
Readfrommaster?
Scalability/capacity
! !
!
!
!
!
Standard MySQL replication:

consistency in practice
ProxySQLGTIDcasualreads:
• Appliestosameconnectiononly.
• Ifmasterwithinhostgroup,canfailbacktomaster
• NotCAPConsistent.Aproxyisn’taknowncomponentinCAP
Theorem.


https://proxysql.com/blog/proxysql-gtid-causal-reads
! !
!
!
!
!
"
Standard MySQL replication:

consistency in practice
! !
!
!
!
!
frenotomonitorreplicationlag:
• Suggestswhenreplicasareuptodate
• HAProxyroutesqueriestoreplicas,offloadingtrafficfrom
master
• NotCAPConsistent.NotpartofCAP.


https://githubengineering.com/mitigating-replication-lag-and-reducing-read-load-with-freno/
"
Semi-sync replication
Singlemaster,multiplereplicas,semi-synctoall/subsetof
replicas.
! !
!
!
!
!
Semi-sync replication:

CAP properties
StillnotConsistent.
• Thoughwegetdurability.
StillnotAvailable.
• semi-syncwriteAvailabilitydependsonconfiguration;on
identitiesofsemi-syncreplicas.
! !
!
!
!
!
Hybrid cluster
IsitCA?IsitCP?
Dependsongeographiclocation,time,workload.
! !
!
!
!
!
Vitess
SQLlayes:vttablet,proxytobackend
MySQLstandardreplicationbackendshards
Suggestedconfiguration:
• semi-sync
• onlysendtraffictomaster
" "
"
!
!
!
!
!
!
Vitess:
CAP properties
Givensuggestedconfiguration:
• NotConsistent
• NotAvailable
" "
"
!
!
!
!
!
!
But!
Withfailover,wecanhavethesystemhighlyavailable.
Withreads-on-masteroranotherproxysolution,wecanmake
thesystemhighlyconsistent.
" "
"
!
!
!
!
!
!
CAP != E=MC²
InnoDB Cluster, single writer
Singlewriternode,paxosconsensus
! !
!
< 8.0.14
InnoDB Cluster, single writer:
CAP properties
NotAvailable:ifnetworkpartitionedseverely,quorumcanbe
lostandnoleadertoacceptwrites.
NotConsistent;changesare:
• propagatedtomajorityofnodes,notall.
• madedurable,notapplied.
! !
!
< 8.0.14
InnoDB Cluster, single writer:
availability, consistency in practice
MySQLRouterasProxy,routetraffictoleader.
ProxySQLforper-connectionconsistentreads.! !
!
"
< 8.0.14
InnoDB Cluster, multi writer
Multiwriternodes,paxosconsensus
! !
!
< 8.0.14
InnoDB Cluster, multi writer:
CAP properties
NotAvailable,asbefore.
• Debatable:arewriteconflictscompatiblewithAvailability?
Notconsistent,asbefore.
! !
!
< 8.0.14
Galera:
CAP properties
wsrep_sync_wait=0
• NotAvailable,notConsistent
wsrep_sync_wait != 0 (e.g.=3)
• NotAvailable
• Consistentuptotimeoutonisolatednodes:i.e.not
Consistent.
! !
!
InnoDB Cluster, >= 8.0.14
group_replication_consistency= BEFORE_AND_AFTER
Supportsconsistentreads,uptotimeoutonisolatednode.
NotAvailable,notConsistent.
STONITHforisolatednodes.
! !
!
Is there any AP setup?
AP setups
Disjointmasters
! !!
! !!
! !
!
! ! Writablemaster-master,asyncreplication
Writablecircular[n>2]mastertopology,asyncreplication
Takeaways
MathandEngineeringarenotrequiredtoagree.Practical
engneeringmakestradeoffs.
CAPTheoremdoesnotrepresentcomplexproductionsystems,
nordoesitmeetproductionrequirements.
CAPTheoremmaynotevenapplytoyoursystem.Itmightnot
bethemodelweshouldbelookingat.
EvenasCAPsaysyouhavetochooseAoverCincaseofP,it
doesnotmeanyoucannotachievehighavailabilityandhigh
consistency.
PACELC
AnextentiontoCAP:
-ifPartitioned,tradeAvailabilityforConsistency.
-Else,tradeLatencyforConsistency
Morerealistic,stilldoesnotmeetproductionneeds.
Harvest, Yield, and ScalableTolerant Systems,ArmandoFox,EricA.Brewer

https://pdfs.semanticscholar.org/5015/8bc1a8a67295ab7bce0550886a9859000dc2.pdf
Brewer’s Conjecture and the Feasibility of Consistent, Available, Partition-TolerantWeb
Services,SethGilbert,NancyLynch

https://www.glassbeam.com/sites/all/themes/glassbeam/images/blog/10.1.1.67.6951.pdf
A Critique of the CAPTheorem,MartinKleppmann

https://arxiv.org/pdf/1509.05393.pdf
CAPTwelve Years Later: How the "Rules" Have Changed,EricBrewer

https://www.infoq.com/articles/cap-twelve-years-later-how-the-rules-have-changed
Please stop calling databases CP or AP,MartinKleppmann

https://martin.kleppmann.com/2015/05/11/please-stop-calling-databases-cp-or-ap.html
Further reading
NewSQL database systems are failing to guarantee consistency, and I blame Spanner,Daniel
Abadi

http://dbmsmusings.blogspot.com/2018/09/newsql-database-systems-are-failing-to.html
Problems with CAP, andYahoo’s little known NoSQL system,DanielAbadi

http://dbmsmusings.blogspot.com/2010/04/problems-with-cap-and-yahoos-little.html
PACELC theorem,Wikipedia

https://en.wikipedia.org/wiki/PACELC_theorem
Further reading
CAP theorem is mostly misunderstood,SuguSougoumarane

http://ssougou.blogspot.com/2017/09/cap-theorem-is-mostly-misunderstood.html
"A Critique of the CAPTheorem”,JuliaEvans

https://jvns.ca/blog/2016/11/19/a-critique-of-the-cap-theorem/
CAPTheorem,FoundationDB

https://apple.github.io/foundationdb/cap-theorem.html
Further reading
Questions?
github.com/shlomi-noach
@ShlomiNoach
Thank you!

Más contenido relacionado

Último

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Último (20)

Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 

Destacado

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 

Destacado (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

MySQL and the CAP theorem: relevance & misconceptions