SlideShare a Scribd company logo
1 of 41
Download to read offline
Roger	
  Bodamer
roger@10gen.com
    @rogerb
Thoughts on Transaction
          and
  Consistency Models
The database world is changing
Document Datastores, Key Value, Graph databases
The database world is changing
         Transactional model
The database world is changing
            Full Acid
The database world is changing
CAP
It is impossible in the asynchronous network model to
implement a read/write data object that guarantees the
following properties:
• Availability
• Atomic consistency in all fair executions (including those
in which messages are lost).
CAP
  It is impossible in the asynchronous network model to
  implement a read/write data object that guarantees the
  following properties:
  • Availability
  • Atomic consistency in all fair executions (including those
  in which messages are lost).

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

But we get to define “won’t work”
Consistency Models - CAP

• Choices are Available-P (AP) or Consistent-P (CP)
• Write Availability, not Read Availability, is the Main Question

• It’s not all about CAP
   Scale, Reduced latency:
       •Multi data center
       •Speed
       •Even load distribution
Examples of Eventually
          Consistent Systems

• Eventual Consistency:
   •“The storage system guarantees that if no new
   updates are made to the object, eventually all
   accesses will return the last updated value”

•Examples:
   • DNS
   • Async replication (RDBMS, MongoDB)
   • Memcached (TTL cache)
Eventual Consistency
Eventual Consistency




Read(x)	
  :	
  1,	
  2,	
  2,	
  4,	
  4,	
  4,	
  4	
  …
Could we get this?




Read(x)	
  :	
  1,	
  2,	
  1,	
  4,	
  2,	
  4,	
  4,	
  4	
  …
Monotonic read consistency
Prevent	
  seeing	
  writes	
  out	
  of	
  order

                                 • Appserver and slave on same
                                 box
                                 • Appserver only reads from Slave

                                 • Eventually consistent
                                 • Guaranteed to see reads in
                                 order

                                 • Failover ?
RYOW Consistency
                                                             • Read Your Own
                                                 Primary     Writes
Read	
  /	
  	
  Has	
  Written
                                   Replication               • Eventually consistent
                                                             for readers
                                                 Secondary   • Immediately
                                                             consistent for writers
   Read
Amazon Dynamo

•R: # of servers to read from
•W: # servers to get response from
•N: Replication factor
   • R+W>N has nice properties
Example
Example	
  1

R	
  +	
  W	
  <=	
  N

R	
  =	
  1
W	
  =	
  1
N	
  =	
  5

Possibly	
  Stale	
  data
Higher	
  availability
Example
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, we can’t
       have both fast local
       reads and writes at
       the same time if all
       the data centers are
       equal peers
Consistency levels
• Strong: W + R > N
• Weak / Eventual : W + R <= N
• Optimized Read: R=1, W=N
• Optimized Write: W=1, R=N
Multi Datacenter Strategies
• DR
   • Failover
• Single Region, Multi Datacenter
   • Useful for Strong or Eventual Consistency
• Local Reads, Remote Writes
   • All writes to master on WAN, EC on Slaves
• Intelligent Homing
   • Master copy close to user location
Network Partitions
Network Write Possibilities
•Deny all writes
   • Still Read fully consistent data
   • Give up write Availability
Network Write Possibilities
•Deny all writes
   • Still Read fully consistent data
   • Give up write Availability

•Allow writes on one side
   • Failover
   • Possible to allow reads on other side
Network Write Possibilities
•Deny all writes
   • Still Read fully consistent data
   • Give up write Availability

•Allow writes on one side
   • Failover
   • Possible to allow reads on other side

•Allow writes on both sides
   • Available
   • Give up consistency
Multiple Writer Strategies
• Last one wins
   • Use Vector clocks to decide latest

• Insert
     Inserts often really means
       if ( !exists(x)) then set(x)
    exists is hard to implement in eventually
    consistent systems
Multiple Writer Strategies
• Delete
    op1: set( { _id : 'joe', age : 40 } }
    op2: delete( { _id : 'joe' } )
    op3: set( { _id : 'joe', age : 33 } )
• Consider switching 2 and 3
• Tombstone: Remember delete, and apply last-operation-wins

• Update
 update users set age=40 where _id=’joe’
However:
 op1: update users set age=40 where _id='joe'
 op2: update users set state='ca' where _id='joe'
Multiple Writer Strategies
• Programatic Merge
   • Store operations, instead of state
   • Replay operations
   • Did you get the last operation ?
   • Not immediate

•Communtative operations
   • Conflict free?
   • Fold-able
   • Example: add, increment, decrement
Trivial Network Partitions
MongoDB Options
MongoDB Transaction Support
• Single Master / Sharded

• MongoDB Supports Atomic Operations on Single Documents
   • But not Rollback
• $ operators
   • $set, $unset, $inc, $push, $pushall, $pull, $pullall
• Update if current
   • find followed by update
• Find and modify
MongoDB


                               Primary
Read	
  /	
  Write
MongoDB


                                       Primary
Read	
  /	
  Write
                         Replication


                                       Secondary


                         Replication


                                       Secondary	
  for	
  Backup
MongoDB


                                       Primary
Read	
  /	
  Write
                         Replication


                                       Secondary


     Read                Replication


                                       Secondary	
  for	
  Backup
MongoDB
                         Replicaset

                                       Primary
Read	
  /	
  Write
                         Replication


                                       Secondary


     Read                Replication


                                       Secondary	
  for	
  Backup
Write Scalability: Sharding
read      key	
  range	
      key	
  range	
      key	
  range	
  
            0	
  ..	
  30      31	
  ..	
  60      61	
  ..	
  100

         ReplicaSet	
  1     ReplicaSet	
  2     ReplicaSet	
  3



          Primary              Primary            Primary


         Secondary           Secondary           Secondary


         Secondary           Secondary           Secondary



                                                                     write
Sometimes we need global state /
      more consistency
•Unique key constraints
   •User registration
•ACL changes
Could it be the case that…


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

where uptime:= system is up and non-buggy?
Thank You :-)
  @rogerb
download at mongodb.org

                conferences,	
  appearances,	
  and	
  meetups
                                         http://www.10gen.com/events




    Facebook	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  |	
  	
  	
  	
  	
  	
  	
  	
  	
  Twitter	
  	
  	
  	
  	
  	
  	
  	
  	
  |	
  	
  	
  	
  	
  	
  	
  	
  	
  LinkedIn
http://bit.ly/mongoU	
                                                        @mongodb                                          http://linkd.in/joinmongo

More Related Content

Similar to Consistency-New-Generation-Databases

What every developer should know about database scalability, PyCon 2010
What every developer should know about database scalability, PyCon 2010What every developer should know about database scalability, PyCon 2010
What every developer should know about database scalability, PyCon 2010
jbellis
 
Replication Solutions for PostgreSQL
Replication Solutions for PostgreSQLReplication Solutions for PostgreSQL
Replication Solutions for PostgreSQL
Peter Eisentraut
 
MongoDB Use Cases: Healthcare, CMS, Analytics
MongoDB Use Cases: Healthcare, CMS, AnalyticsMongoDB Use Cases: Healthcare, CMS, Analytics
MongoDB Use Cases: Healthcare, CMS, Analytics
MongoDB
 
SQL 2012 AlwaysOn Availability Groups (AOAGs) for SharePoint Farms - Norcall ...
SQL 2012 AlwaysOn Availability Groups (AOAGs) for SharePoint Farms - Norcall ...SQL 2012 AlwaysOn Availability Groups (AOAGs) for SharePoint Farms - Norcall ...
SQL 2012 AlwaysOn Availability Groups (AOAGs) for SharePoint Farms - Norcall ...
Michael Noel
 

Similar to Consistency-New-Generation-Databases (20)

Thoughts on consistency models
Thoughts on consistency modelsThoughts on consistency models
Thoughts on consistency models
 
What every developer should know about database scalability, PyCon 2010
What every developer should know about database scalability, PyCon 2010What every developer should know about database scalability, PyCon 2010
What every developer should know about database scalability, PyCon 2010
 
Drop the Pressure on your Production Server
Drop the Pressure on your Production ServerDrop the Pressure on your Production Server
Drop the Pressure on your Production Server
 
Replication, Durability, and Disaster Recovery
Replication, Durability, and Disaster RecoveryReplication, Durability, and Disaster Recovery
Replication, Durability, and Disaster Recovery
 
MongoDB Replication fundamentals - Desert Code Camp - October 2014
MongoDB Replication fundamentals - Desert Code Camp - October 2014MongoDB Replication fundamentals - Desert Code Camp - October 2014
MongoDB Replication fundamentals - Desert Code Camp - October 2014
 
MongoDB World 2018: Active-Active Application Architectures: Become a MongoDB...
MongoDB World 2018: Active-Active Application Architectures: Become a MongoDB...MongoDB World 2018: Active-Active Application Architectures: Become a MongoDB...
MongoDB World 2018: Active-Active Application Architectures: Become a MongoDB...
 
MongoDB Replication fundamentals - Desert Code Camp - October 2014
MongoDB Replication fundamentals - Desert Code Camp - October 2014MongoDB Replication fundamentals - Desert Code Camp - October 2014
MongoDB Replication fundamentals - Desert Code Camp - October 2014
 
Power of the Log: LSM & Append Only Data Structures
Power of the Log: LSM & Append Only Data StructuresPower of the Log: LSM & Append Only Data Structures
Power of the Log: LSM & Append Only Data Structures
 
The Power of the Log
The Power of the LogThe Power of the Log
The Power of the Log
 
Replication Solutions for PostgreSQL
Replication Solutions for PostgreSQLReplication Solutions for PostgreSQL
Replication Solutions for PostgreSQL
 
Scalability, Availability & Stability Patterns
Scalability, Availability & Stability PatternsScalability, Availability & Stability Patterns
Scalability, Availability & Stability Patterns
 
Mongosv 2011 - Replication
Mongosv 2011 - ReplicationMongosv 2011 - Replication
Mongosv 2011 - Replication
 
Application Profiling for Memory and Performance
Application Profiling for Memory and PerformanceApplication Profiling for Memory and Performance
Application Profiling for Memory and Performance
 
Polyglot and Functional Programming (OSCON 2012)
Polyglot and Functional Programming (OSCON 2012)Polyglot and Functional Programming (OSCON 2012)
Polyglot and Functional Programming (OSCON 2012)
 
MongoDB Use Cases: Healthcare, CMS, Analytics
MongoDB Use Cases: Healthcare, CMS, AnalyticsMongoDB Use Cases: Healthcare, CMS, Analytics
MongoDB Use Cases: Healthcare, CMS, Analytics
 
Select Stars: A DBA's Guide to Azure Cosmos DB (SQL Saturday Oslo 2018)
Select Stars: A DBA's Guide to Azure Cosmos DB (SQL Saturday Oslo 2018)Select Stars: A DBA's Guide to Azure Cosmos DB (SQL Saturday Oslo 2018)
Select Stars: A DBA's Guide to Azure Cosmos DB (SQL Saturday Oslo 2018)
 
Concurrency and Multithreading Demistified - Reversim Summit 2014
Concurrency and Multithreading Demistified - Reversim Summit 2014Concurrency and Multithreading Demistified - Reversim Summit 2014
Concurrency and Multithreading Demistified - Reversim Summit 2014
 
SQL 2012 AlwaysOn Availability Groups (AOAGs) for SharePoint Farms - Norcall ...
SQL 2012 AlwaysOn Availability Groups (AOAGs) for SharePoint Farms - Norcall ...SQL 2012 AlwaysOn Availability Groups (AOAGs) for SharePoint Farms - Norcall ...
SQL 2012 AlwaysOn Availability Groups (AOAGs) for SharePoint Farms - Norcall ...
 
Select Stars: A DBA's Guide to Azure Cosmos DB (Chicago Suburban SQL Server U...
Select Stars: A DBA's Guide to Azure Cosmos DB (Chicago Suburban SQL Server U...Select Stars: A DBA's Guide to Azure Cosmos DB (Chicago Suburban SQL Server U...
Select Stars: A DBA's Guide to Azure Cosmos DB (Chicago Suburban SQL Server U...
 
Jay Kreps on Project Voldemort Scaling Simple Storage At LinkedIn
Jay Kreps on Project Voldemort Scaling Simple Storage At LinkedInJay Kreps on Project Voldemort Scaling Simple Storage At LinkedIn
Jay Kreps on Project Voldemort Scaling Simple Storage At LinkedIn
 

More from Roger Xia

机器学习推动金融数据智能
机器学习推动金融数据智能机器学习推动金融数据智能
机器学习推动金融数据智能
Roger Xia
 
Code reviews
Code reviewsCode reviews
Code reviews
Roger Xia
 
Python introduction
Python introductionPython introduction
Python introduction
Roger Xia
 
Learning notes ruby
Learning notes rubyLearning notes ruby
Learning notes ruby
Roger Xia
 
Converged open platform for enterprise
Converged open platform for enterpriseConverged open platform for enterprise
Converged open platform for enterprise
Roger Xia
 
Code reviews
Code reviewsCode reviews
Code reviews
Roger Xia
 
E commerce search strategies
E commerce search strategiesE commerce search strategies
E commerce search strategies
Roger Xia
 
Indefero source code_managment
Indefero source code_managmentIndefero source code_managment
Indefero source code_managment
Roger Xia
 
Web service through cxf
Web service through cxfWeb service through cxf
Web service through cxf
Roger Xia
 

More from Roger Xia (20)

机器学习推动金融数据智能
机器学习推动金融数据智能机器学习推动金融数据智能
机器学习推动金融数据智能
 
Code reviews
Code reviewsCode reviews
Code reviews
 
Python introduction
Python introductionPython introduction
Python introduction
 
Learning notes ruby
Learning notes rubyLearning notes ruby
Learning notes ruby
 
Converged open platform for enterprise
Converged open platform for enterpriseConverged open platform for enterprise
Converged open platform for enterprise
 
Code reviews
Code reviewsCode reviews
Code reviews
 
E commerce search strategies
E commerce search strategiesE commerce search strategies
E commerce search strategies
 
Saml
SamlSaml
Saml
 
JavaEE6
JavaEE6JavaEE6
JavaEE6
 
Indefero source code_managment
Indefero source code_managmentIndefero source code_managment
Indefero source code_managment
 
Web Services Atomic Transactio
 Web Services Atomic Transactio Web Services Atomic Transactio
Web Services Atomic Transactio
 
Web service through cxf
Web service through cxfWeb service through cxf
Web service through cxf
 
Spring one2gx2010 spring-nonrelational_data
Spring one2gx2010 spring-nonrelational_dataSpring one2gx2010 spring-nonrelational_data
Spring one2gx2010 spring-nonrelational_data
 
Java explore
Java exploreJava explore
Java explore
 
Mongo db实战
Mongo db实战Mongo db实战
Mongo db实战
 
Ca siteminder
Ca siteminderCa siteminder
Ca siteminder
 
Fixing twitter
Fixing twitterFixing twitter
Fixing twitter
 
Eclipse plug in mylyn & tasktop
Eclipse plug in mylyn & tasktopEclipse plug in mylyn & tasktop
Eclipse plug in mylyn & tasktop
 
新浪微博架构猜想
新浪微博架构猜想新浪微博架构猜想
新浪微博架构猜想
 
构建高效能的Web网站 精选版-by-infoq
构建高效能的Web网站 精选版-by-infoq构建高效能的Web网站 精选版-by-infoq
构建高效能的Web网站 精选版-by-infoq
 

Recently uploaded

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 

Recently uploaded (20)

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
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
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
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
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 

Consistency-New-Generation-Databases

  • 2. Thoughts on Transaction and Consistency Models
  • 3. The database world is changing Document Datastores, Key Value, Graph databases
  • 4. The database world is changing Transactional model
  • 5. The database world is changing Full Acid
  • 6. The database world is changing
  • 7. CAP It is impossible in the asynchronous network model to implement a read/write data object that guarantees the following properties: • Availability • Atomic consistency in all fair executions (including those in which messages are lost).
  • 8. CAP It is impossible in the asynchronous network model to implement a read/write data object that guarantees the following properties: • Availability • Atomic consistency in all fair executions (including those in which messages are lost). Or: If the network is broken, your database won’t work But we get to define “won’t work”
  • 9. Consistency Models - CAP • Choices are Available-P (AP) or Consistent-P (CP) • Write Availability, not Read Availability, is the Main Question • It’s not all about CAP Scale, Reduced latency: •Multi data center •Speed •Even load distribution
  • 10. Examples of Eventually Consistent Systems • Eventual Consistency: •“The storage system guarantees that if no new updates are made to the object, eventually all accesses will return the last updated value” •Examples: • DNS • Async replication (RDBMS, MongoDB) • Memcached (TTL cache)
  • 12. Eventual Consistency Read(x)  :  1,  2,  2,  4,  4,  4,  4  …
  • 13. Could we get this? Read(x)  :  1,  2,  1,  4,  2,  4,  4,  4  …
  • 14. Monotonic read consistency Prevent  seeing  writes  out  of  order • Appserver and slave on same box • Appserver only reads from Slave • Eventually consistent • Guaranteed to see reads in order • Failover ?
  • 15. RYOW Consistency • Read Your Own Primary Writes Read  /    Has  Written Replication • Eventually consistent for readers Secondary • Immediately consistent for writers Read
  • 16. Amazon Dynamo •R: # of servers to read from •W: # servers to get response from •N: Replication factor • R+W>N has nice properties
  • 17. Example Example  1 R  +  W  <=  N R  =  1 W  =  1 N  =  5 Possibly  Stale  data Higher  availability
  • 18. Example 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
  • 19. R+W>N If R+W > N, we can’t have both fast local reads and writes at the same time if all the data centers are equal peers
  • 20. Consistency levels • Strong: W + R > N • Weak / Eventual : W + R <= N • Optimized Read: R=1, W=N • Optimized Write: W=1, R=N
  • 21. Multi Datacenter Strategies • DR • Failover • Single Region, Multi Datacenter • Useful for Strong or Eventual Consistency • Local Reads, Remote Writes • All writes to master on WAN, EC on Slaves • Intelligent Homing • Master copy close to user location
  • 23. Network Write Possibilities •Deny all writes • Still Read fully consistent data • Give up write Availability
  • 24. Network Write Possibilities •Deny all writes • Still Read fully consistent data • Give up write Availability •Allow writes on one side • Failover • Possible to allow reads on other side
  • 25. Network Write Possibilities •Deny all writes • Still Read fully consistent data • Give up write Availability •Allow writes on one side • Failover • Possible to allow reads on other side •Allow writes on both sides • Available • Give up consistency
  • 26. Multiple Writer Strategies • Last one wins • Use Vector clocks to decide latest • Insert Inserts often really means if ( !exists(x)) then set(x) exists is hard to implement in eventually consistent systems
  • 27. Multiple Writer Strategies • Delete op1: set( { _id : 'joe', age : 40 } } op2: delete( { _id : 'joe' } ) op3: set( { _id : 'joe', age : 33 } ) • Consider switching 2 and 3 • Tombstone: Remember delete, and apply last-operation-wins • Update update users set age=40 where _id=’joe’ However: op1: update users set age=40 where _id='joe' op2: update users set state='ca' where _id='joe'
  • 28. Multiple Writer Strategies • Programatic Merge • Store operations, instead of state • Replay operations • Did you get the last operation ? • Not immediate •Communtative operations • Conflict free? • Fold-able • Example: add, increment, decrement
  • 31. MongoDB Transaction Support • Single Master / Sharded • MongoDB Supports Atomic Operations on Single Documents • But not Rollback • $ operators • $set, $unset, $inc, $push, $pushall, $pull, $pullall • Update if current • find followed by update • Find and modify
  • 32. MongoDB Primary Read  /  Write
  • 33. MongoDB Primary Read  /  Write Replication Secondary Replication Secondary  for  Backup
  • 34. MongoDB Primary Read  /  Write Replication Secondary Read Replication Secondary  for  Backup
  • 35. MongoDB Replicaset Primary Read  /  Write Replication Secondary Read Replication Secondary  for  Backup
  • 36. Write Scalability: Sharding read key  range   key  range   key  range   0  ..  30 31  ..  60 61  ..  100 ReplicaSet  1 ReplicaSet  2 ReplicaSet  3 Primary Primary Primary Secondary Secondary Secondary Secondary Secondary Secondary write
  • 37.
  • 38. Sometimes we need global state / more consistency •Unique key constraints •User registration •ACL changes
  • 39. Could it be the case that… uptime( CP + average developer ) >= uptime( AP + average developer ) where uptime:= system is up and non-buggy?
  • 40. Thank You :-) @rogerb
  • 41. download at mongodb.org conferences,  appearances,  and  meetups http://www.10gen.com/events Facebook                    |                  Twitter                  |                  LinkedIn http://bit.ly/mongoU   @mongodb http://linkd.in/joinmongo