SlideShare a Scribd company logo
cap
cap theorem


• Eric Brewer (ex-Inktomi)
• Proved by Lynch and Gilbert
cap theorem
It is impossible in the asynchrounous network
    model to implement a read/write object
    that garantuees the following properties:

               - Availability
  - Atomic consistency in fair transactions

        Or: If the network is broken,
         your database won’t work
AP vs CP

• Real choices are
 • Available - Partition
 • Consistent - Partion
AP
• Multiple Nodes participate in writes
• System will be Eventually Consistent
 • Storage System guarantees if there are no
    new updates, all reads will eventually
    return the same, last updated value
Examples:
- DNS
- ASync replication
- MongoDB with Slave-OK
- Memcache
eventual consistency
                        Master




               Slave              Slave




               Client             Client



Asuming update 1,2,3,4,5
Client will expect 1,2,2,2,3,4,5,5,5
eventual consistency
                       Master




              Slave             Slave




              Client            Client



However, we could get this: 1,2,2,4,2,5
eventual consistency

• Monotonic read consistency
• Pin client to certain slave / app server
 • Failover still fails
multi master
Dynamo model

R - number of servers to read from
W - number of servers to get response from
N - Replication Factor

R + W > N has nice properties
multi master
Example 1             Example 2
R + W <= N            R +W > N
R=1                   R=2         R =1
W=1                   W=1         W=2
N=5                   N=2         N=2
Possibly Stale Data   ‘Consistent’ Data
Higher Availability
R +W > N
      If R + W > N you can’t both
     have fast local reads and writes
network partitions
trivial network
    partition
network write
        possibilities
• deny all writes
 • read fully consistent data
• allow writes on one side
 • allow reads on other side (stale)
• allow writes on both sides
 • give up consistency
multiple writer strategies
 •   Last one wins

     •   vector clocks

 •   Insert

     •   insert often means:

         •   if (!exist(x)) set(x)

         •   exist is hard to implement in eventually
             consistent systems
delete
op1: set joe, age 40
op2: delete joe
op3: set joe, 41

- consider switching 2 and 3
- tombstone: remember delete and apply last op
wins
multiple writer strategies
•   programmatic merge

    •   store ops instead of state

    •   replay operations

        •   did I get the last one ?


•   Commutative operations

    •   conflict free

    •   anything that’s foldable
CP

• Sometimes we need global state
• Unique - constraints
• User registration
• ACL changes
Finally

uptime(CP + average developer)
>=
uptime(AP + average developer)

Where uptime is the system is up and non-buggy

More Related Content

What's hot (19)

PPTX
When it Absolutely, Positively, Has to be There: Reliability Guarantees in Ka...
confluent
 
PDF
Extreme HTTP Performance Tuning: 1.2M API req/s on a 4 vCPU EC2 Instance
ScyllaDB
 
PPTX
SignalFx Kafka Consumer Optimization
SignalFx
 
PDF
Whoops! I Rewrote It in Rust
ScyllaDB
 
PDF
Get Lower Latency and Higher Throughput for Java Applications
ScyllaDB
 
PPTX
How to manage large amounts of data with akka streams
Igor Mielientiev
 
PPTX
MySQL Multi-Master Replication
Michael Naumov
 
PDF
Rust, Wright's Law, and the Future of Low-Latency Systems
ScyllaDB
 
PDF
DB Latency Using DRAM + PMem in App Direct & Memory Modes
ScyllaDB
 
PDF
Rust Is Safe. But Is It Fast?
ScyllaDB
 
PDF
Kafka At Scale in the Cloud
confluent
 
PPTX
Rust kafka-5-2019-unskip
Gerard Klijs
 
PPTX
Basics of Node.js
Alper Unal
 
PDF
Data Structures for High Resolution, Real-time Telemetry at Scale
ScyllaDB
 
PDF
Vanquishing Latency Outliers in the Lightbits LightOS Software Defined Storag...
ScyllaDB
 
PPTX
Keeping MongoDB Data Safe
Tony Tam
 
PDF
Inter-process communication on steroids
Roberto Agostino Vitillo
 
PDF
Crimson: Ceph for the Age of NVMe and Persistent Memory
ScyllaDB
 
PDF
Seastore: Next Generation Backing Store for Ceph
ScyllaDB
 
When it Absolutely, Positively, Has to be There: Reliability Guarantees in Ka...
confluent
 
Extreme HTTP Performance Tuning: 1.2M API req/s on a 4 vCPU EC2 Instance
ScyllaDB
 
SignalFx Kafka Consumer Optimization
SignalFx
 
Whoops! I Rewrote It in Rust
ScyllaDB
 
Get Lower Latency and Higher Throughput for Java Applications
ScyllaDB
 
How to manage large amounts of data with akka streams
Igor Mielientiev
 
MySQL Multi-Master Replication
Michael Naumov
 
Rust, Wright's Law, and the Future of Low-Latency Systems
ScyllaDB
 
DB Latency Using DRAM + PMem in App Direct & Memory Modes
ScyllaDB
 
Rust Is Safe. But Is It Fast?
ScyllaDB
 
Kafka At Scale in the Cloud
confluent
 
Rust kafka-5-2019-unskip
Gerard Klijs
 
Basics of Node.js
Alper Unal
 
Data Structures for High Resolution, Real-time Telemetry at Scale
ScyllaDB
 
Vanquishing Latency Outliers in the Lightbits LightOS Software Defined Storag...
ScyllaDB
 
Keeping MongoDB Data Safe
Tony Tam
 
Inter-process communication on steroids
Roberto Agostino Vitillo
 
Crimson: Ceph for the Age of NVMe and Persistent Memory
ScyllaDB
 
Seastore: Next Generation Backing Store for Ceph
ScyllaDB
 

Similar to Thoughts on consistency models (20)

PDF
Thoughts on Transaction and Consistency Models
iammutex
 
PDF
Consistency-New-Generation-Databases
Roger Xia
 
PDF
Consistency Models in New Generation Databases
iammutex
 
PDF
Jay Kreps on Project Voldemort Scaling Simple Storage At LinkedIn
LinkedIn
 
PPTX
Ch-7-Part-2-Distributed-System.pptx
Kabindra Koirala
 
PDF
Making the Most Out of ScyllaDB's Awesome Concurrency at Optimizely
ScyllaDB
 
PDF
Seek and Destroy Kafka Under Replication
HostedbyConfluent
 
PDF
Salvatore Sanfilippo – How Redis Cluster works, and why - NoSQL matters Barce...
NoSQLmatters
 
PDF
NoSQL afternoon in Japan Kumofs & MessagePack
Sadayuki Furuhashi
 
PDF
NoSQL afternoon in Japan kumofs & MessagePack
Sadayuki Furuhashi
 
PDF
Scylla Summit 2016: Outbrain Case Study - Lowering Latency While Doing 20X IO...
ScyllaDB
 
PDF
Call me maybe: Jepsen and flaky networks
Shalin Shekhar Mangar
 
PPTX
Eventual Consistency @WalmartLabs with Kafka, Avro, SolrCloud and Hadoop
Ayon Sinha
 
KEY
Replication, Durability, and Disaster Recovery
Steven Francia
 
PDF
Disaggregated Networking - The Drivers, the Software & The High Availability
Open Networking Summit
 
PDF
Distributed and concurrent programming with RabbitMQ and EventMachine Rails U...
Paolo Negri
 
PDF
3.2 Streaming and Messaging
振东 刘
 
PDF
Cpu Caches
shinolajla
 
PDF
CPU Caches - Jamie Allen
jaxconf
 
PDF
Highly concurrent yet natural programming
Infinit
 
Thoughts on Transaction and Consistency Models
iammutex
 
Consistency-New-Generation-Databases
Roger Xia
 
Consistency Models in New Generation Databases
iammutex
 
Jay Kreps on Project Voldemort Scaling Simple Storage At LinkedIn
LinkedIn
 
Ch-7-Part-2-Distributed-System.pptx
Kabindra Koirala
 
Making the Most Out of ScyllaDB's Awesome Concurrency at Optimizely
ScyllaDB
 
Seek and Destroy Kafka Under Replication
HostedbyConfluent
 
Salvatore Sanfilippo – How Redis Cluster works, and why - NoSQL matters Barce...
NoSQLmatters
 
NoSQL afternoon in Japan Kumofs & MessagePack
Sadayuki Furuhashi
 
NoSQL afternoon in Japan kumofs & MessagePack
Sadayuki Furuhashi
 
Scylla Summit 2016: Outbrain Case Study - Lowering Latency While Doing 20X IO...
ScyllaDB
 
Call me maybe: Jepsen and flaky networks
Shalin Shekhar Mangar
 
Eventual Consistency @WalmartLabs with Kafka, Avro, SolrCloud and Hadoop
Ayon Sinha
 
Replication, Durability, and Disaster Recovery
Steven Francia
 
Disaggregated Networking - The Drivers, the Software & The High Availability
Open Networking Summit
 
Distributed and concurrent programming with RabbitMQ and EventMachine Rails U...
Paolo Negri
 
3.2 Streaming and Messaging
振东 刘
 
Cpu Caches
shinolajla
 
CPU Caches - Jamie Allen
jaxconf
 
Highly concurrent yet natural programming
Infinit
 
Ad

More from rogerbodamer (6)

PDF
Intro to MongoDB and datamodeling
rogerbodamer
 
KEY
Thoughts on MongoDB Analytics
rogerbodamer
 
PPT
Mongo Web Apps: OSCON 2011
rogerbodamer
 
PDF
Mongo db japan
rogerbodamer
 
PDF
Deployment
rogerbodamer
 
KEY
Schema Design with MongoDB
rogerbodamer
 
Intro to MongoDB and datamodeling
rogerbodamer
 
Thoughts on MongoDB Analytics
rogerbodamer
 
Mongo Web Apps: OSCON 2011
rogerbodamer
 
Mongo db japan
rogerbodamer
 
Deployment
rogerbodamer
 
Schema Design with MongoDB
rogerbodamer
 
Ad

Recently uploaded (20)

PDF
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
PDF
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
PDF
State-Dependent Conformal Perception Bounds for Neuro-Symbolic Verification
Ivan Ruchkin
 
PPTX
The Future of AI & Machine Learning.pptx
pritsen4700
 
PDF
GDG Cloud Munich - Intro - Luiz Carneiro - #BuildWithAI - July - Abdel.pdf
Luiz Carneiro
 
PPTX
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
PDF
Researching The Best Chat SDK Providers in 2025
Ray Fields
 
PPTX
Agile Chennai 18-19 July 2025 | Workshop - Enhancing Agile Collaboration with...
AgileNetwork
 
PPTX
Simple and concise overview about Quantum computing..pptx
mughal641
 
PDF
introduction to computer hardware and sofeware
chauhanshraddha2007
 
PDF
OFFOFFBOX™ – A New Era for African Film | Startup Presentation
ambaicciwalkerbrian
 
PPTX
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
PDF
Per Axbom: The spectacular lies of maps
Nexer Digital
 
PDF
Brief History of Internet - Early Days of Internet
sutharharshit158
 
PDF
Generative AI vs Predictive AI-The Ultimate Comparison Guide
Lily Clark
 
PDF
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
PPTX
Introduction to Flutter by Ayush Desai.pptx
ayushdesai204
 
PPTX
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
PDF
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
PDF
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
State-Dependent Conformal Perception Bounds for Neuro-Symbolic Verification
Ivan Ruchkin
 
The Future of AI & Machine Learning.pptx
pritsen4700
 
GDG Cloud Munich - Intro - Luiz Carneiro - #BuildWithAI - July - Abdel.pdf
Luiz Carneiro
 
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
Researching The Best Chat SDK Providers in 2025
Ray Fields
 
Agile Chennai 18-19 July 2025 | Workshop - Enhancing Agile Collaboration with...
AgileNetwork
 
Simple and concise overview about Quantum computing..pptx
mughal641
 
introduction to computer hardware and sofeware
chauhanshraddha2007
 
OFFOFFBOX™ – A New Era for African Film | Startup Presentation
ambaicciwalkerbrian
 
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
Per Axbom: The spectacular lies of maps
Nexer Digital
 
Brief History of Internet - Early Days of Internet
sutharharshit158
 
Generative AI vs Predictive AI-The Ultimate Comparison Guide
Lily Clark
 
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
Introduction to Flutter by Ayush Desai.pptx
ayushdesai204
 
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 

Thoughts on consistency models

  • 1. cap
  • 2. cap theorem • Eric Brewer (ex-Inktomi) • Proved by Lynch and Gilbert
  • 3. cap theorem It is impossible in the asynchrounous network model to implement a read/write object that garantuees the following properties: - Availability - Atomic consistency in fair transactions Or: If the network is broken, your database won’t work
  • 4. AP vs CP • Real choices are • Available - Partition • Consistent - Partion
  • 5. AP • Multiple Nodes participate in writes • System will be Eventually Consistent • Storage System guarantees if there are no new updates, all reads will eventually return the same, last updated value Examples: - DNS - ASync replication - MongoDB with Slave-OK - Memcache
  • 6. eventual consistency Master Slave Slave Client Client Asuming update 1,2,3,4,5 Client will expect 1,2,2,2,3,4,5,5,5
  • 7. eventual consistency Master Slave Slave Client Client However, we could get this: 1,2,2,4,2,5
  • 8. eventual consistency • Monotonic read consistency • Pin client to certain slave / app server • Failover still fails
  • 9. multi master Dynamo model R - number of servers to read from W - number of servers to get response from N - Replication Factor R + W > N has nice properties
  • 10. multi master Example 1 Example 2 R + W <= N R +W > N R=1 R=2 R =1 W=1 W=1 W=2 N=5 N=2 N=2 Possibly Stale Data ‘Consistent’ Data Higher Availability
  • 11. R +W > N If R + W > N you can’t both have fast local reads and writes
  • 13. trivial network partition
  • 14. network write possibilities • deny all writes • read fully consistent data • allow writes on one side • allow reads on other side (stale) • allow writes on both sides • give up consistency
  • 15. multiple writer strategies • Last one wins • vector clocks • Insert • insert often means: • if (!exist(x)) set(x) • exist is hard to implement in eventually consistent systems
  • 16. delete op1: set joe, age 40 op2: delete joe op3: set joe, 41 - consider switching 2 and 3 - tombstone: remember delete and apply last op wins
  • 17. multiple writer strategies • programmatic merge • store ops instead of state • replay operations • did I get the last one ? • Commutative operations • conflict free • anything that’s foldable
  • 18. CP • Sometimes we need global state • Unique - constraints • User registration • ACL changes
  • 19. Finally uptime(CP + average developer) >= uptime(AP + average developer) Where uptime is the system is up and non-buggy