SlideShare una empresa de Scribd logo
1 de 21
CAP:理论与实践




童家旺
http://www.dbthink.com/
Weibo: jametong
内容大纲
   CAP的历史沿革
   CAP原理介绍
   CAP,Pick Two?
   CAP权衡中的经济考量
   CAP与ACID的关系
   分区只是另一段Code Path
   CAP在实践中的应用
   参考资料
CAP原理的历史
   1997年,Fox & Brewer提出BASE概念
       《Cluster-Based Scalable Network Services》
   1999年,Fox & Brewer 提出CAP Principle
       《Harvest, Yield, and Scalable Tolerant Systems》
   2000年,PODC的Keynotes,正式提出CAP
       《Towards Robust Distributed Systems》
   2002年,Seth Gilbert & Nancy Lynch证明CAP
       《Brewer’s Conjecture and the Feasibility of
        Consistent, Available, Partition-Tolerant Web Services》
CAP流行的几大推手
   OSDI 2006,Google发布Bigtable的论文
       Bigtable: A Distributed Storage System for Structured Data
   SOSP 2007,Amazon发布Dynamo的论文
       Dynamo: Amazon’s Highly Available Key-value Store
   2007年8月,Amazon的Werner Vogels推介CAP
       Availability & Consistency
   2007年10月,Werner Vogels撰文介绍最终一致性
       Eventually Consistent
   2008年1月,Ebay的架构师Dan Prichett介绍BASE
       BASE: An Acid Alternative
CAP Theorem
   对于共享的数据系统,仅能同时满足2项:
       Consistency (多节点看到数据的单一/同一副本)
         Full Consistency?
         Casual Consistency?
         Timeline Consistency?
         Eventual Consistency?
       Availability (系统总是可以执行变更操作)
           牺牲10秒钟的A?牺牲10分钟的A?
       Partition Tolerance
   在广域网的情况下,分区不可避免
       => consistency vs. availability
CAP ,Pick Two?
   Traditional databases guarantee consistency.
   The CAP theorem tells you that you cannot
    have consistency, availability, and fault-
    tolerance at the same time.
   But we want to build scalable databases, so
    we forget about consistency.
   Oh and by the way, who needs consistency
    anyway?
面对P,真的必须牺牲一致性吗?
   新浪微博可以丢吗?
   淘宝的商品信息可以暂时不一致吗?
   12306提供的库存信息可以不准确吗?
   比特币(bitcoin)可以不准确吗?
   中行信用卡可以不一致吗?
Reliability & $$
数据状态机的分类

   何谓状态机
     简单的理解是,计算机中会发生变化的数据都是状态机,
      这个数据的值不同可能会带来不同的后果。
     分类:按照三个维度:时间、信息含金量、变更频率

持续时间     信息含金量   变更频繁度   例子
瞬时       高       少       Shopping Card Session(分)
瞬时       低       少       Login Cookie(分)
中等时长     高       少       Ecommerce Billing(天)
中等时长     中       少       Product Catalog(年)
中等时长     高       多       Flight/Train Inventory (月)
无限时长     中       少       User Profile(年)
无限时长     高       多       Bank Account Balance(年))
其实,CAP并没有声明…
   放弃一致性
     不一致应该仅仅是个例外

     很多系统牺牲的内容远远超过必要!

   放弃事务 (ACID)
     需要调整C与I的预期   (仅仅)
   不要使用SQL
     很多NOSQL系统中也开始支持SQL

     声明性语言(SQL)与CAP配合良好
CAP与ACID
   当系统没有Partition时:
     支持Full   ACID
   当系统出现Partition时:
     Atomic:不同的分区还是应该保持Atomic

     Consistent:临时违背(如:没有重复?)

     Isolation:临时牺牲隔离性

     Durable:永远不该牺牲它(需要保留它用)
像程序员一样思考

分区只是个不同的代码路径
User Profile处理

            APP
                                                 Cache
           Server

Write to
Master, When      Reading From arbitrary
Failed, Fail      node
the Request


                          Read      Read      Read       Read
Backup         Master
                          Slave     Slave     Slave      Slave


                        Near Real Time Redo

    Always Relaxing Read Consistency
                        Shipping
Message Processing

                   App Server
                                      Persistent Message in arbitrary
                                      Message Node
                                      When One Failed Just Pick Next

       Msg       Msg            Msg         Msg
       DB1       DB2            DB3         DB4




       DB1       DB2        DB3             DB4
      Backup    Backup     Backup          Backup

 When One Node Failed, Just Delay the
 Message Sending Persistent in that Node,
 Aka, Sacrificing Availability
Shopping Cart

                      Writing         Reading


  Write multiple
  replicas to multi                         Merging multiple
  node, If one                              replicas from multi
  node Fails, Just                          node, if one node
  Skip it.                                  Fails, just ignore it.




                      DB1       DB2   DB3



      Relaxing Consistency When Partitioned
银行ATM机

            When Partitioned
              只允许低于200$的提现操作
              在本地记录操作的日志

            When Partition Recovered
              Reapply本地日志
              如果有透支,通过外部商业
               流程进行补偿处理。
            Sacrifice Some A,Relax
             Some Consistency
航空订票系统
            超卖是一种商业选择
              仅限经济舱

            如果出现超卖
              为用户做免费升舱

            When Partition
              Relaxing
                   Consistency
              一定的补偿机制
CAP的实际含义
总结
   CAP的实际效果
     探索适合不同应用的一致性与可用性平衡

   在没有分区发生时
     可以同时满足C与A,以及完整的ACID事务支持

     可以选择牺牲一定的C,获得更好的性能与扩展性

   分区发生时,选择A(集中关注分区的恢复)
     需要有分区开始前、进行中、恢复后的处理策略

     应用合适的补偿处理机制
参考资料
   NoSQL: Past, Present, Future
     By   Eric Brewer
   CAP Twelve Years Later: How the "Rules"
    Have Changed
     By   Eric Brewer
   Towards Robust Distributed Systems
     By   Eric Brewer
   Dynamo: Amazon's Highly Available Key-
    value Store
     By   Giuseppe DeCandia, Werner Vogels etc..
Any Questions?

Más contenido relacionado

Destacado

高级服务器设计和实现2
高级服务器设计和实现2高级服务器设计和实现2
高级服务器设计和实现2Feng Yu
 
高级服务器设计和实现1
高级服务器设计和实现1高级服务器设计和实现1
高级服务器设计和实现1Feng Yu
 
Erlang全接触
Erlang全接触Erlang全接触
Erlang全接触Feng Yu
 
Tsung 压力测试工具
Tsung 压力测试工具Tsung 压力测试工具
Tsung 压力测试工具Feng Yu
 
高级服务器设计和实现3
高级服务器设计和实现3高级服务器设计和实现3
高级服务器设计和实现3Feng Yu
 
利用新硬件提升数据库性能
利用新硬件提升数据库性能利用新硬件提升数据库性能
利用新硬件提升数据库性能Feng Yu
 
MySQL和IO(上)
MySQL和IO(上)MySQL和IO(上)
MySQL和IO(上)Feng Yu
 
了解集群
了解集群了解集群
了解集群Feng Yu
 
低成本和高性能MySQL云架构探索
低成本和高性能MySQL云架构探索低成本和高性能MySQL云架构探索
低成本和高性能MySQL云架构探索Feng Yu
 
mnesia脑裂问题综述
mnesia脑裂问题综述mnesia脑裂问题综述
mnesia脑裂问题综述Feng Yu
 
Flash存储设备在淘宝的应用实践
Flash存储设备在淘宝的应用实践Flash存储设备在淘宝的应用实践
Flash存储设备在淘宝的应用实践Feng Yu
 
Cpu高效编程技术
Cpu高效编程技术Cpu高效编程技术
Cpu高效编程技术Feng Yu
 
SSD在淘宝的应用实践
SSD在淘宝的应用实践SSD在淘宝的应用实践
SSD在淘宝的应用实践Feng Yu
 
Erlang开发实践
Erlang开发实践Erlang开发实践
Erlang开发实践Feng Yu
 
C1000K高性能服务器构建技术
C1000K高性能服务器构建技术C1000K高性能服务器构建技术
C1000K高性能服务器构建技术Feng Yu
 
Systemtap
SystemtapSystemtap
SystemtapFeng Yu
 
我为什么要选择RabbitMQ
我为什么要选择RabbitMQ我为什么要选择RabbitMQ
我为什么要选择RabbitMQFeng Yu
 
了解网络
了解网络了解网络
了解网络Feng Yu
 
Linux architecture
Linux architectureLinux architecture
Linux architecturemcganesh
 

Destacado (19)

高级服务器设计和实现2
高级服务器设计和实现2高级服务器设计和实现2
高级服务器设计和实现2
 
高级服务器设计和实现1
高级服务器设计和实现1高级服务器设计和实现1
高级服务器设计和实现1
 
Erlang全接触
Erlang全接触Erlang全接触
Erlang全接触
 
Tsung 压力测试工具
Tsung 压力测试工具Tsung 压力测试工具
Tsung 压力测试工具
 
高级服务器设计和实现3
高级服务器设计和实现3高级服务器设计和实现3
高级服务器设计和实现3
 
利用新硬件提升数据库性能
利用新硬件提升数据库性能利用新硬件提升数据库性能
利用新硬件提升数据库性能
 
MySQL和IO(上)
MySQL和IO(上)MySQL和IO(上)
MySQL和IO(上)
 
了解集群
了解集群了解集群
了解集群
 
低成本和高性能MySQL云架构探索
低成本和高性能MySQL云架构探索低成本和高性能MySQL云架构探索
低成本和高性能MySQL云架构探索
 
mnesia脑裂问题综述
mnesia脑裂问题综述mnesia脑裂问题综述
mnesia脑裂问题综述
 
Flash存储设备在淘宝的应用实践
Flash存储设备在淘宝的应用实践Flash存储设备在淘宝的应用实践
Flash存储设备在淘宝的应用实践
 
Cpu高效编程技术
Cpu高效编程技术Cpu高效编程技术
Cpu高效编程技术
 
SSD在淘宝的应用实践
SSD在淘宝的应用实践SSD在淘宝的应用实践
SSD在淘宝的应用实践
 
Erlang开发实践
Erlang开发实践Erlang开发实践
Erlang开发实践
 
C1000K高性能服务器构建技术
C1000K高性能服务器构建技术C1000K高性能服务器构建技术
C1000K高性能服务器构建技术
 
Systemtap
SystemtapSystemtap
Systemtap
 
我为什么要选择RabbitMQ
我为什么要选择RabbitMQ我为什么要选择RabbitMQ
我为什么要选择RabbitMQ
 
了解网络
了解网络了解网络
了解网络
 
Linux architecture
Linux architectureLinux architecture
Linux architecture
 

Similar a Cap 理论与实践

Dreaming Infrastructure
Dreaming InfrastructureDreaming Infrastructure
Dreaming Infrastructurekyhpudding
 
Big Data, NoSQL, and MongoDB
Big Data, NoSQL, and MongoDBBig Data, NoSQL, and MongoDB
Big Data, NoSQL, and MongoDBMonster Supreme
 
淘宝Java中间件之路 it168
淘宝Java中间件之路 it168淘宝Java中间件之路 it168
淘宝Java中间件之路 it168vanadies10
 
Cassandra简介.ppt
Cassandra简介.pptCassandra简介.ppt
Cassandra简介.pptjames tong
 
Pegasus: Designing a Distributed Key Value System (Arch summit beijing-2016)
Pegasus: Designing a Distributed Key Value System (Arch summit beijing-2016)Pegasus: Designing a Distributed Key Value System (Arch summit beijing-2016)
Pegasus: Designing a Distributed Key Value System (Arch summit beijing-2016)涛 吴
 
浅谈电商网站数据访问层(DAL)与 ORM 之适用性
浅谈电商网站数据访问层(DAL)与 ORM 之适用性浅谈电商网站数据访问层(DAL)与 ORM 之适用性
浅谈电商网站数据访问层(DAL)与 ORM 之适用性Xuefeng Zhang
 
20141128(刘胜)UTC2014分布式和云服务的思考与实践——支付清算行业分布式架构的探索
20141128(刘胜)UTC2014分布式和云服务的思考与实践——支付清算行业分布式架构的探索20141128(刘胜)UTC2014分布式和云服务的思考与实践——支付清算行业分布式架构的探索
20141128(刘胜)UTC2014分布式和云服务的思考与实践——支付清算行业分布式架构的探索liu sheng
 
Taobao数据库这5年
Taobao数据库这5年Taobao数据库这5年
Taobao数据库这5年yp_fangdong
 
优酷 Web网站架构案例分析
优酷   Web网站架构案例分析优酷   Web网站架构案例分析
优酷 Web网站架构案例分析George Ang
 
Key value store
Key value storeKey value store
Key value storexuanhan863
 
Youku arch qcon2009_beijing
Youku arch qcon2009_beijingYouku arch qcon2009_beijing
Youku arch qcon2009_beijingdrewz lin
 
Ceph Day Shanghai - Ceph in Chinau Unicom Labs
Ceph Day Shanghai - Ceph in Chinau Unicom LabsCeph Day Shanghai - Ceph in Chinau Unicom Labs
Ceph Day Shanghai - Ceph in Chinau Unicom LabsCeph Community
 
百度分布式数据库平台
百度分布式数据库平台百度分布式数据库平台
百度分布式数据库平台Wyatt Fang
 
深入研究雲端應用程式平台-AppFabric
深入研究雲端應用程式平台-AppFabric深入研究雲端應用程式平台-AppFabric
深入研究雲端應用程式平台-AppFabricJohn Chang
 
Ibm solid db overview v6.3 20090320
Ibm solid db overview v6.3 20090320Ibm solid db overview v6.3 20090320
Ibm solid db overview v6.3 20090320小新 制造
 

Similar a Cap 理论与实践 (20)

Dreaming Infrastructure
Dreaming InfrastructureDreaming Infrastructure
Dreaming Infrastructure
 
Big Data, NoSQL, and MongoDB
Big Data, NoSQL, and MongoDBBig Data, NoSQL, and MongoDB
Big Data, NoSQL, and MongoDB
 
淘宝Java中间件之路 it168
淘宝Java中间件之路 it168淘宝Java中间件之路 it168
淘宝Java中间件之路 it168
 
Cassandra简介.ppt
Cassandra简介.pptCassandra简介.ppt
Cassandra简介.ppt
 
Cdc@ganji.com
Cdc@ganji.comCdc@ganji.com
Cdc@ganji.com
 
Pegasus: Designing a Distributed Key Value System (Arch summit beijing-2016)
Pegasus: Designing a Distributed Key Value System (Arch summit beijing-2016)Pegasus: Designing a Distributed Key Value System (Arch summit beijing-2016)
Pegasus: Designing a Distributed Key Value System (Arch summit beijing-2016)
 
浅谈电商网站数据访问层(DAL)与 ORM 之适用性
浅谈电商网站数据访问层(DAL)与 ORM 之适用性浅谈电商网站数据访问层(DAL)与 ORM 之适用性
浅谈电商网站数据访问层(DAL)与 ORM 之适用性
 
20141128(刘胜)UTC2014分布式和云服务的思考与实践——支付清算行业分布式架构的探索
20141128(刘胜)UTC2014分布式和云服务的思考与实践——支付清算行业分布式架构的探索20141128(刘胜)UTC2014分布式和云服务的思考与实践——支付清算行业分布式架构的探索
20141128(刘胜)UTC2014分布式和云服务的思考与实践——支付清算行业分布式架构的探索
 
Taobao数据库这5年
Taobao数据库这5年Taobao数据库这5年
Taobao数据库这5年
 
优酷 Web网站架构案例分析
优酷   Web网站架构案例分析优酷   Web网站架构案例分析
优酷 Web网站架构案例分析
 
Key value store
Key value storeKey value store
Key value store
 
Youku arch qcon2009_beijing
Youku arch qcon2009_beijingYouku arch qcon2009_beijing
Youku arch qcon2009_beijing
 
Erlang and HTML5
Erlang and HTML5Erlang and HTML5
Erlang and HTML5
 
Dell
DellDell
Dell
 
No sql数据库笔谈
No sql数据库笔谈No sql数据库笔谈
No sql数据库笔谈
 
Ceph Day Shanghai - Ceph in Chinau Unicom Labs
Ceph Day Shanghai - Ceph in Chinau Unicom LabsCeph Day Shanghai - Ceph in Chinau Unicom Labs
Ceph Day Shanghai - Ceph in Chinau Unicom Labs
 
百度分布式数据库平台
百度分布式数据库平台百度分布式数据库平台
百度分布式数据库平台
 
Exodus2 大局观
Exodus2 大局观Exodus2 大局观
Exodus2 大局观
 
深入研究雲端應用程式平台-AppFabric
深入研究雲端應用程式平台-AppFabric深入研究雲端應用程式平台-AppFabric
深入研究雲端應用程式平台-AppFabric
 
Ibm solid db overview v6.3 20090320
Ibm solid db overview v6.3 20090320Ibm solid db overview v6.3 20090320
Ibm solid db overview v6.3 20090320
 

Más de james tong

数据库系统设计漫谈
数据库系统设计漫谈数据库系统设计漫谈
数据库系统设计漫谈james tong
 
Migrating from MySQL to PostgreSQL
Migrating from MySQL to PostgreSQLMigrating from MySQL to PostgreSQL
Migrating from MySQL to PostgreSQLjames tong
 
Oracle 性能优化
Oracle 性能优化Oracle 性能优化
Oracle 性能优化james tong
 
Scalable system operations presentation
Scalable system operations presentationScalable system operations presentation
Scalable system operations presentationjames tong
 
Benchmarks, performance, scalability, and capacity what s behind the numbers...
Benchmarks, performance, scalability, and capacity  what s behind the numbers...Benchmarks, performance, scalability, and capacity  what s behind the numbers...
Benchmarks, performance, scalability, and capacity what s behind the numbers...james tong
 
Stability patterns presentation
Stability patterns presentationStability patterns presentation
Stability patterns presentationjames tong
 
The right read optimization is actually write optimization
The right read optimization is actually write optimizationThe right read optimization is actually write optimization
The right read optimization is actually write optimizationjames tong
 
My sql ssd-mysqluc-2012
My sql ssd-mysqluc-2012My sql ssd-mysqluc-2012
My sql ssd-mysqluc-2012james tong
 
Evaluating ha alternatives my sql tutorial2
Evaluating ha alternatives my sql tutorial2Evaluating ha alternatives my sql tutorial2
Evaluating ha alternatives my sql tutorial2james tong
 
Troubleshooting mysql-tutorial
Troubleshooting mysql-tutorialTroubleshooting mysql-tutorial
Troubleshooting mysql-tutorialjames tong
 
Understanding performance through_measurement
Understanding performance through_measurementUnderstanding performance through_measurement
Understanding performance through_measurementjames tong
 
我对后端优化的一点想法 (2012)
我对后端优化的一点想法 (2012)我对后端优化的一点想法 (2012)
我对后端优化的一点想法 (2012)james tong
 
设计可扩展的Oracle应用
设计可扩展的Oracle应用设计可扩展的Oracle应用
设计可扩展的Oracle应用james tong
 
我对后端优化的一点想法.pptx
我对后端优化的一点想法.pptx我对后端优化的一点想法.pptx
我对后端优化的一点想法.pptxjames tong
 
Enqueue Lock介绍.ppt
Enqueue Lock介绍.pptEnqueue Lock介绍.ppt
Enqueue Lock介绍.pptjames tong
 
Oracle数据库体系结构简介.ppt
Oracle数据库体系结构简介.pptOracle数据库体系结构简介.ppt
Oracle数据库体系结构简介.pptjames tong
 

Más de james tong (16)

数据库系统设计漫谈
数据库系统设计漫谈数据库系统设计漫谈
数据库系统设计漫谈
 
Migrating from MySQL to PostgreSQL
Migrating from MySQL to PostgreSQLMigrating from MySQL to PostgreSQL
Migrating from MySQL to PostgreSQL
 
Oracle 性能优化
Oracle 性能优化Oracle 性能优化
Oracle 性能优化
 
Scalable system operations presentation
Scalable system operations presentationScalable system operations presentation
Scalable system operations presentation
 
Benchmarks, performance, scalability, and capacity what s behind the numbers...
Benchmarks, performance, scalability, and capacity  what s behind the numbers...Benchmarks, performance, scalability, and capacity  what s behind the numbers...
Benchmarks, performance, scalability, and capacity what s behind the numbers...
 
Stability patterns presentation
Stability patterns presentationStability patterns presentation
Stability patterns presentation
 
The right read optimization is actually write optimization
The right read optimization is actually write optimizationThe right read optimization is actually write optimization
The right read optimization is actually write optimization
 
My sql ssd-mysqluc-2012
My sql ssd-mysqluc-2012My sql ssd-mysqluc-2012
My sql ssd-mysqluc-2012
 
Evaluating ha alternatives my sql tutorial2
Evaluating ha alternatives my sql tutorial2Evaluating ha alternatives my sql tutorial2
Evaluating ha alternatives my sql tutorial2
 
Troubleshooting mysql-tutorial
Troubleshooting mysql-tutorialTroubleshooting mysql-tutorial
Troubleshooting mysql-tutorial
 
Understanding performance through_measurement
Understanding performance through_measurementUnderstanding performance through_measurement
Understanding performance through_measurement
 
我对后端优化的一点想法 (2012)
我对后端优化的一点想法 (2012)我对后端优化的一点想法 (2012)
我对后端优化的一点想法 (2012)
 
设计可扩展的Oracle应用
设计可扩展的Oracle应用设计可扩展的Oracle应用
设计可扩展的Oracle应用
 
我对后端优化的一点想法.pptx
我对后端优化的一点想法.pptx我对后端优化的一点想法.pptx
我对后端优化的一点想法.pptx
 
Enqueue Lock介绍.ppt
Enqueue Lock介绍.pptEnqueue Lock介绍.ppt
Enqueue Lock介绍.ppt
 
Oracle数据库体系结构简介.ppt
Oracle数据库体系结构简介.pptOracle数据库体系结构简介.ppt
Oracle数据库体系结构简介.ppt
 

Cap 理论与实践

  • 2. 内容大纲  CAP的历史沿革  CAP原理介绍  CAP,Pick Two?  CAP权衡中的经济考量  CAP与ACID的关系  分区只是另一段Code Path  CAP在实践中的应用  参考资料
  • 3. CAP原理的历史  1997年,Fox & Brewer提出BASE概念  《Cluster-Based Scalable Network Services》  1999年,Fox & Brewer 提出CAP Principle  《Harvest, Yield, and Scalable Tolerant Systems》  2000年,PODC的Keynotes,正式提出CAP  《Towards Robust Distributed Systems》  2002年,Seth Gilbert & Nancy Lynch证明CAP  《Brewer’s Conjecture and the Feasibility of Consistent, Available, Partition-Tolerant Web Services》
  • 4. CAP流行的几大推手  OSDI 2006,Google发布Bigtable的论文  Bigtable: A Distributed Storage System for Structured Data  SOSP 2007,Amazon发布Dynamo的论文  Dynamo: Amazon’s Highly Available Key-value Store  2007年8月,Amazon的Werner Vogels推介CAP  Availability & Consistency  2007年10月,Werner Vogels撰文介绍最终一致性  Eventually Consistent  2008年1月,Ebay的架构师Dan Prichett介绍BASE  BASE: An Acid Alternative
  • 5. CAP Theorem  对于共享的数据系统,仅能同时满足2项:  Consistency (多节点看到数据的单一/同一副本)  Full Consistency?  Casual Consistency?  Timeline Consistency?  Eventual Consistency?  Availability (系统总是可以执行变更操作)  牺牲10秒钟的A?牺牲10分钟的A?  Partition Tolerance  在广域网的情况下,分区不可避免  => consistency vs. availability
  • 6. CAP ,Pick Two?  Traditional databases guarantee consistency.  The CAP theorem tells you that you cannot have consistency, availability, and fault- tolerance at the same time.  But we want to build scalable databases, so we forget about consistency.  Oh and by the way, who needs consistency anyway?
  • 7. 面对P,真的必须牺牲一致性吗?  新浪微博可以丢吗?  淘宝的商品信息可以暂时不一致吗?  12306提供的库存信息可以不准确吗?  比特币(bitcoin)可以不准确吗?  中行信用卡可以不一致吗?
  • 9. 数据状态机的分类  何谓状态机  简单的理解是,计算机中会发生变化的数据都是状态机, 这个数据的值不同可能会带来不同的后果。  分类:按照三个维度:时间、信息含金量、变更频率 持续时间 信息含金量 变更频繁度 例子 瞬时 高 少 Shopping Card Session(分) 瞬时 低 少 Login Cookie(分) 中等时长 高 少 Ecommerce Billing(天) 中等时长 中 少 Product Catalog(年) 中等时长 高 多 Flight/Train Inventory (月) 无限时长 中 少 User Profile(年) 无限时长 高 多 Bank Account Balance(年))
  • 10. 其实,CAP并没有声明…  放弃一致性  不一致应该仅仅是个例外  很多系统牺牲的内容远远超过必要!  放弃事务 (ACID)  需要调整C与I的预期 (仅仅)  不要使用SQL  很多NOSQL系统中也开始支持SQL  声明性语言(SQL)与CAP配合良好
  • 11. CAP与ACID  当系统没有Partition时:  支持Full ACID  当系统出现Partition时:  Atomic:不同的分区还是应该保持Atomic  Consistent:临时违背(如:没有重复?)  Isolation:临时牺牲隔离性  Durable:永远不该牺牲它(需要保留它用)
  • 13. User Profile处理 APP Cache Server Write to Master, When Reading From arbitrary Failed, Fail node the Request Read Read Read Read Backup Master Slave Slave Slave Slave Near Real Time Redo Always Relaxing Read Consistency Shipping
  • 14. Message Processing App Server Persistent Message in arbitrary Message Node When One Failed Just Pick Next Msg Msg Msg Msg DB1 DB2 DB3 DB4 DB1 DB2 DB3 DB4 Backup Backup Backup Backup When One Node Failed, Just Delay the Message Sending Persistent in that Node, Aka, Sacrificing Availability
  • 15. Shopping Cart Writing Reading Write multiple replicas to multi Merging multiple node, If one replicas from multi node Fails, Just node, if one node Skip it. Fails, just ignore it. DB1 DB2 DB3 Relaxing Consistency When Partitioned
  • 16. 银行ATM机  When Partitioned  只允许低于200$的提现操作  在本地记录操作的日志  When Partition Recovered  Reapply本地日志  如果有透支,通过外部商业 流程进行补偿处理。  Sacrifice Some A,Relax Some Consistency
  • 17. 航空订票系统  超卖是一种商业选择  仅限经济舱  如果出现超卖  为用户做免费升舱  When Partition  Relaxing Consistency  一定的补偿机制
  • 19. 总结  CAP的实际效果  探索适合不同应用的一致性与可用性平衡  在没有分区发生时  可以同时满足C与A,以及完整的ACID事务支持  可以选择牺牲一定的C,获得更好的性能与扩展性  分区发生时,选择A(集中关注分区的恢复)  需要有分区开始前、进行中、恢复后的处理策略  应用合适的补偿处理机制
  • 20. 参考资料  NoSQL: Past, Present, Future  By Eric Brewer  CAP Twelve Years Later: How the "Rules" Have Changed  By Eric Brewer  Towards Robust Distributed Systems  By Eric Brewer  Dynamo: Amazon's Highly Available Key- value Store  By Giuseppe DeCandia, Werner Vogels etc..