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

PPTX
Deep Dive into Apache Kafka
PDF
Introduction to Akka-Streams
PDF
Building your own Distributed System The easy way - Cassandra Summit EU 2014
PPTX
Streaming and Messaging
PDF
Using eBPF to Measure the k8s Cluster Health
PDF
High-Performance Networking Using eBPF, XDP, and io_uring
PDF
Stateful stream processing with kafka and samza
PDF
Keeping Latency Low and Throughput High with Application-level Priority Manag...
Deep Dive into Apache Kafka
Introduction to Akka-Streams
Building your own Distributed System The easy way - Cassandra Summit EU 2014
Streaming and Messaging
Using eBPF to Measure the k8s Cluster Health
High-Performance Networking Using eBPF, XDP, and io_uring
Stateful stream processing with kafka and samza
Keeping Latency Low and Throughput High with Application-level Priority Manag...

What's hot (19)

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

Similar to Thoughts on consistency models (20)

PDF
Consistency Models in New Generation Databases
PDF
Consistency-New-Generation-Databases
PDF
Thoughts on Transaction and Consistency Models
PPT
Big Data & NoSQL - EFS'11 (Pavlo Baron)
PPTX
cse40822-CAP.pptx
PPTX
CAP Theorem - Theory, Implications and Practices
PDF
From Mainframe to Microservice: An Introduction to Distributed Systems
PPT
Handling Data in Mega Scale Web Systems
ODP
Distributed systems and consistency
ODP
Distributed Systems
PDF
Distributed System explained (with NodeJS) - Bruno Bossola - Codemotion Milan...
PPT
Distributed System by Pratik Tambekar
PDF
Distributed Systems explained (with NodeJS) - Bruno Bossola, JUG Torino
PPTX
Put Your Thinking CAP On
PDF
GoshawkDB: Making Time with Vector Clocks
PDF
Design Patterns For Distributed NO-reational databases
PDF
Jay Kreps on Project Voldemort Scaling Simple Storage At LinkedIn
KEY
Eventually Consistent Data Structures (from strangeloop12)
PDF
Automated conflict resolution - enabling masterless data distribution (Rune S...
PDF
The CAP Theorem
Consistency Models in New Generation Databases
Consistency-New-Generation-Databases
Thoughts on Transaction and Consistency Models
Big Data & NoSQL - EFS'11 (Pavlo Baron)
cse40822-CAP.pptx
CAP Theorem - Theory, Implications and Practices
From Mainframe to Microservice: An Introduction to Distributed Systems
Handling Data in Mega Scale Web Systems
Distributed systems and consistency
Distributed Systems
Distributed System explained (with NodeJS) - Bruno Bossola - Codemotion Milan...
Distributed System by Pratik Tambekar
Distributed Systems explained (with NodeJS) - Bruno Bossola, JUG Torino
Put Your Thinking CAP On
GoshawkDB: Making Time with Vector Clocks
Design Patterns For Distributed NO-reational databases
Jay Kreps on Project Voldemort Scaling Simple Storage At LinkedIn
Eventually Consistent Data Structures (from strangeloop12)
Automated conflict resolution - enabling masterless data distribution (Rune S...
The CAP Theorem
Ad

More from rogerbodamer (6)

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

Recently uploaded (20)

PDF
Spectral efficient network and resource selection model in 5G networks
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Empathic Computing: Creating Shared Understanding
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Approach and Philosophy of On baking technology
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
sap open course for s4hana steps from ECC to s4
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
KodekX | Application Modernization Development
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Unlocking AI with Model Context Protocol (MCP)
PPT
Teaching material agriculture food technology
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Spectral efficient network and resource selection model in 5G networks
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Empathic Computing: Creating Shared Understanding
The AUB Centre for AI in Media Proposal.docx
Agricultural_Statistics_at_a_Glance_2022_0.pdf
“AI and Expert System Decision Support & Business Intelligence Systems”
Approach and Philosophy of On baking technology
Network Security Unit 5.pdf for BCA BBA.
Diabetes mellitus diagnosis method based random forest with bat algorithm
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Programs and apps: productivity, graphics, security and other tools
sap open course for s4hana steps from ECC to s4
The Rise and Fall of 3GPP – Time for a Sabbatical?
20250228 LYD VKU AI Blended-Learning.pptx
KodekX | Application Modernization Development
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
Unlocking AI with Model Context Protocol (MCP)
Teaching material agriculture food technology
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...

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