SlideShare a Scribd company logo
1 of 37
Download to read offline
#MongoDBTokyo




Replication and Replica Sets
Steve Francia
Chief Evangelist, 10gen
Agenda
•  Replica Sets Lifecycle
•  Developing with Replica Sets
•  Operational Considerations
•  Behind the Curtain
Why Replication?
•  How many have faced node failures?
•  How many have been woken up from sleep to do
 a fail-over(s)?
•  How many have experienced issues due to
 network latency?
•  Different uses for data
   –  Normal processing
   –  Simple analytics
ReplicaSet Lifecycle
Node 1            Node 2




                Node 3




Replica Set – Creation
Node 1                             Node 2
       Secondary                         Secondary
                          Heartbeat

           Re




                                           n
                                           tio
              pli




                                        ica
                  cat




                                         pl
                  on  i




                                      Re
                          Node 3
                           Primary




Replica Set – Initialize
Primary Election
       Node 1                         Node 2
       Secondary      Heartbeat       Secondary




                      Node 3




Replica Set – Failure
Replication
       Node 1                    Node 2
       Secondary                 Primary
                   Heartbeat




                   Node 3




Replica Set – Failover
Replication
       Node 1                      Node 2
       Secondary                    Primary
                   Heartbeat




                                        n
                                    tio
                                   ica
                                    pl
                                 Re
                   Node 3
                   Recovery




Replica Set – Recovery
Replication
       Node 1                      Node 2
       Secondary                    Primary
                   Heartbeat




                                        n
                                    tio
                                   ica
                                    pl
                                 Re
                   Node 3
                   Secondary




Replica Set – Recovered
ReplicaSet Roles &
Configuration
Node 1                         Node 2
       Secondary                      Arbiter
                          Heartbeat

           Re
              pli
                  cat
                  on  i

                          Node 3
                           Primary




Replica Set Roles
Configuration Options
> conf = {
        _id : "mySet",
        members : [
            {_id : 0, host : "A”, priority : 3},
            {_id : 1, host : "B", priority : 2},
            {_id : 2, host : "C”},
            {_id : 3, host : "D", hidden : true},
            {_id : 4, host : "E", hidden : true, slaveDelay :
3600}
    ]
}


> rs.initiate(conf)
Configuration Options
> conf = {
        _id : "mySet”,
        members : [                  Primary DC
            {_id : 0, host : "A”, priority : 3},
            {_id : 1, host : "B", priority : 2},
            {_id : 2, host : "C”},
            {_id : 3, host : "D", hidden : true},
            {_id : 4, host : "E", hidden : true, slaveDelay :
3600}
    ]
}


> rs.initiate(conf)
Configuration Options
> conf = {
                                                        Secondary DC
        _id : "mySet”,                              Default Priority = 1
        members : [
            {_id : 0, host : "A”, priority : 3},
            {_id : 1, host : "B", priority : 2},
            {_id : 2, host : "C”},
            {_id : 3, host : "D", hidden : true},
            {_id : 4, host : "E", hidden : true, slaveDelay :
3600}
    ]
}


> rs.initiate(conf)
Configuration Options
> conf = {
        _id : "mySet”,
        members : [
            {_id : 0, host : "A”, priority : 3},     Analytics
            {_id : 1, host : "B", priority : 2},       node
            {_id : 2, host : "C”},
            {_id : 3, host : "D", hidden : true},
            {_id : 4, host : "E", hidden : true, slaveDelay :
3600}
    ]
}


> rs.initiate(conf)
Configuration Options
> conf = {
        _id : "mySet”,
        members : [
            {_id : 0, host : "A”, priority : 3},
            {_id : 1, host : "B", priority : 2},
            {_id : 2, host : "C”},
            {_id : 3, host : "D", hidden : true},
            {_id : 4, host : "E", hidden : true, slaveDelay :
3600}
    ]
}
                                              Backup node

> rs.initiate(conf)
Developing with Replica Sets
Client Application
                        Driver




                    Write




                                 Read
                       Primary



        Secondary                       Secondary



Strong Consistency
Client Application
                    Driver




                        Write
          ad




                                    Re
        Re




                                       ad
                    Primary



       Secondary                Secondary



Delayed Consistency
Write Concern
•  Network acknowledgement
•  Wait for error
•  Wait for journal sync
•  Wait for replication
Driver



           write

 Primary

                   apply in
                    memory




Unacknowledged
Driver




            getLastError
  Primary

            apply in
             memory




MongoDB Acknowledged (wait for error)
Driver




                    getLastError


                                   j:true
            write
  Primary

                    apply in                write to
                     memory                  journal




Wait for Journal Sync
Driver




                     getLastError
             write




                                    w:2
  Primary




                                          replicate
                     apply in
                      memory



 Secondary




Wait for Replication
Tagging
•  New in 2.0.0
•  Control where data is written to, and read from
•  Each member can have one or more tags
   –  tags: {dc: "ny"}
   –  tags: {dc: "ny",
            subnet: "192.168",
            rack: "row3rk7"}
•  Replica set defines rules for write concerns
•  Rules can change without changing app code
Tagging Example
{
    _id : "mySet",
    members : [
        {_id : 0, host : "A",   tags    :   {"dc":   "ny"}},
        {_id : 1, host : "B",   tags    :   {"dc":   "ny"}},
        {_id : 2, host : "C",   tags    :   {"dc":   "sf"}},
        {_id : 3, host : "D",   tags    :   {"dc":   "sf"}},
        {_id : 4, host : "E",   tags    :   {"dc":   "cloud"}}],
    settings : {
        getLastErrorModes : {
            allDCs : {"dc" :    3},
            someDCs : {"dc" :   2}} }
}
> db.blogs.insert({...})
> db.runCommand({getLastError : 1, w : "someDCs"})
Driver




                              getLastError


                                             W:allDCs
                     write
  Primary (SF)




                                                        replicate
                             apply in
                              memory


 Secondary (NY)




                                                                    replicate
 Secondary (Cloud)




Wait for Replication (Tagging)
Read Preference Modes
•  5 modes (new in 2.2)
   –  primary (only) - Default
   –  primaryPreferred
   –  secondary
   –  secondaryPreferred
   –  Nearest

   When more than one node is possible, closest node is used for
   reads (all modes but primary)
Tagged Read Preference
•  Custom read preferences
•  Control where you read from by (node) tags
   –  E.g. { "disk": "ssd", "use": "reporting" }

•  Use in conjunction with standard read preferences
   –  Except primary
Operational Considerations
Maintenance and Upgrade
•  No downtime
•  Rolling upgrade/maintenance
   –  Start with Secondary
   –  Primary last
Replica Set – 1 Data Center
                    •  Single datacenter
      Datacenter
                    •  Single switch & power
      Member 1      •  Points of failure:
                       –  Power
      Member 2         –  Network
                       –  Data center
     Datacenter 2
      Member 3         –  Two node failure

                    •  Automatic recovery of
                     single node crash
Replica Set – 2 Data Centers
                    •  Multi data center
     Datacenter 1
                    •  DR node for safety
      Member 1
                    •  Can’t do multi data
      Member 2       center durable write
                     safely since only 1 node
                     in distant DC
     Datacenter 2

      Member 3
Replica Set – 3 Data Centers
     Datacenter 1   •  Three data centers
      Member 1

      Member 2
                    •  Can survive full data
                     center loss
     Datacenter 2
      Member 3      •  Can do w= { dc : 2 } to
      Member 4       guarantee write in 2
                     data centers (with tags)
     Datacenter 3
      Member 5
Just Use It
•  Use replica sets
•  Easy to setup
   –  Try on a single machine

•  Check doc page for RS tutorials
   –  http://docs.mongodb.org/manual/replication/#tutorials
#MongoDBSeoul




Thank You
Steve Francia
Chief Evangelist, 10gen

More Related Content

What's hot

HA Hadoop -ApacheCon talk
HA Hadoop -ApacheCon talkHA Hadoop -ApacheCon talk
HA Hadoop -ApacheCon talkSteve Loughran
 
r2con 2017 r2cLEMENCy
r2con 2017 r2cLEMENCyr2con 2017 r2cLEMENCy
r2con 2017 r2cLEMENCyRay Song
 
Nagios distributed monitoring for web applications
Nagios distributed monitoring for web applicationsNagios distributed monitoring for web applications
Nagios distributed monitoring for web applicationsFernando Honig
 
Encryption Boot Camp on the JVM
Encryption Boot Camp on the JVMEncryption Boot Camp on the JVM
Encryption Boot Camp on the JVMMatthew McCullough
 
동시성과 병렬성
동시성과 병렬성동시성과 병렬성
동시성과 병렬성Chanhyeong LEE
 
Replication and Replica Sets
Replication and Replica SetsReplication and Replica Sets
Replication and Replica SetsMongoDB
 

What's hot (8)

Hadoop Inside
Hadoop InsideHadoop Inside
Hadoop Inside
 
HA Hadoop -ApacheCon talk
HA Hadoop -ApacheCon talkHA Hadoop -ApacheCon talk
HA Hadoop -ApacheCon talk
 
T3dd10 git
T3dd10 gitT3dd10 git
T3dd10 git
 
r2con 2017 r2cLEMENCy
r2con 2017 r2cLEMENCyr2con 2017 r2cLEMENCy
r2con 2017 r2cLEMENCy
 
Nagios distributed monitoring for web applications
Nagios distributed monitoring for web applicationsNagios distributed monitoring for web applications
Nagios distributed monitoring for web applications
 
Encryption Boot Camp on the JVM
Encryption Boot Camp on the JVMEncryption Boot Camp on the JVM
Encryption Boot Camp on the JVM
 
동시성과 병렬성
동시성과 병렬성동시성과 병렬성
동시성과 병렬성
 
Replication and Replica Sets
Replication and Replica SetsReplication and Replica Sets
Replication and Replica Sets
 

Similar to Replication and Replica Sets

Webinar: Replication and Replica Sets
Webinar: Replication and Replica SetsWebinar: Replication and Replica Sets
Webinar: Replication and Replica SetsMongoDB
 
Replication and Replica Sets
Replication and Replica SetsReplication and Replica Sets
Replication and Replica SetsMongoDB
 
Replication and Replica Sets
Replication and Replica SetsReplication and Replica Sets
Replication and Replica SetsMongoDB
 
2013 london advanced-replication
2013 london advanced-replication2013 london advanced-replication
2013 london advanced-replicationMarc Schwering
 
Webinar: Replication and Replica Sets
Webinar: Replication and Replica SetsWebinar: Replication and Replica Sets
Webinar: Replication and Replica SetsMongoDB
 
Replication and replica sets
Replication and replica setsReplication and replica sets
Replication and replica setsRandall Hunt
 
Basic Replication in MongoDB
Basic Replication in MongoDBBasic Replication in MongoDB
Basic Replication in MongoDBMongoDB
 
Replication MongoDB Days 2013
Replication MongoDB Days 2013Replication MongoDB Days 2013
Replication MongoDB Days 2013Randall Hunt
 
Advanced Replication
Advanced ReplicationAdvanced Replication
Advanced ReplicationMongoDB
 
MongoDB London 2013: Basic Replication in MongoDB presented by Marc Schwering...
MongoDB London 2013: Basic Replication in MongoDB presented by Marc Schwering...MongoDB London 2013: Basic Replication in MongoDB presented by Marc Schwering...
MongoDB London 2013: Basic Replication in MongoDB presented by Marc Schwering...MongoDB
 
Webinar: Operational Best Practices
Webinar: Operational Best PracticesWebinar: Operational Best Practices
Webinar: Operational Best PracticesMongoDB
 
Mongosv 2011 - Replication
Mongosv 2011 - ReplicationMongosv 2011 - Replication
Mongosv 2011 - ReplicationJared Rosoff
 
Replica Sets (NYC NoSQL Meetup)
Replica Sets (NYC NoSQL Meetup)Replica Sets (NYC NoSQL Meetup)
Replica Sets (NYC NoSQL Meetup)MongoDB
 
MongoDB Replica Sets
MongoDB Replica SetsMongoDB Replica Sets
MongoDB Replica SetsMongoDB
 
Replication
ReplicationReplication
ReplicationMongoDB
 
Advanced Windows Debugging
Advanced Windows DebuggingAdvanced Windows Debugging
Advanced Windows DebuggingBala Subra
 
Webinar Back to Basics 3 - Introduzione ai Replica Set
Webinar Back to Basics 3 - Introduzione ai Replica SetWebinar Back to Basics 3 - Introduzione ai Replica Set
Webinar Back to Basics 3 - Introduzione ai Replica SetMongoDB
 
MongoDB: Optimising for Performance, Scale & Analytics
MongoDB: Optimising for Performance, Scale & AnalyticsMongoDB: Optimising for Performance, Scale & Analytics
MongoDB: Optimising for Performance, Scale & AnalyticsServer Density
 
Playing CTFs for Fun & Profit
Playing CTFs for Fun & ProfitPlaying CTFs for Fun & Profit
Playing CTFs for Fun & Profitimpdefined
 
MongoDB Best Practices in AWS
MongoDB Best Practices in AWS MongoDB Best Practices in AWS
MongoDB Best Practices in AWS Chris Harris
 

Similar to Replication and Replica Sets (20)

Webinar: Replication and Replica Sets
Webinar: Replication and Replica SetsWebinar: Replication and Replica Sets
Webinar: Replication and Replica Sets
 
Replication and Replica Sets
Replication and Replica SetsReplication and Replica Sets
Replication and Replica Sets
 
Replication and Replica Sets
Replication and Replica SetsReplication and Replica Sets
Replication and Replica Sets
 
2013 london advanced-replication
2013 london advanced-replication2013 london advanced-replication
2013 london advanced-replication
 
Webinar: Replication and Replica Sets
Webinar: Replication and Replica SetsWebinar: Replication and Replica Sets
Webinar: Replication and Replica Sets
 
Replication and replica sets
Replication and replica setsReplication and replica sets
Replication and replica sets
 
Basic Replication in MongoDB
Basic Replication in MongoDBBasic Replication in MongoDB
Basic Replication in MongoDB
 
Replication MongoDB Days 2013
Replication MongoDB Days 2013Replication MongoDB Days 2013
Replication MongoDB Days 2013
 
Advanced Replication
Advanced ReplicationAdvanced Replication
Advanced Replication
 
MongoDB London 2013: Basic Replication in MongoDB presented by Marc Schwering...
MongoDB London 2013: Basic Replication in MongoDB presented by Marc Schwering...MongoDB London 2013: Basic Replication in MongoDB presented by Marc Schwering...
MongoDB London 2013: Basic Replication in MongoDB presented by Marc Schwering...
 
Webinar: Operational Best Practices
Webinar: Operational Best PracticesWebinar: Operational Best Practices
Webinar: Operational Best Practices
 
Mongosv 2011 - Replication
Mongosv 2011 - ReplicationMongosv 2011 - Replication
Mongosv 2011 - Replication
 
Replica Sets (NYC NoSQL Meetup)
Replica Sets (NYC NoSQL Meetup)Replica Sets (NYC NoSQL Meetup)
Replica Sets (NYC NoSQL Meetup)
 
MongoDB Replica Sets
MongoDB Replica SetsMongoDB Replica Sets
MongoDB Replica Sets
 
Replication
ReplicationReplication
Replication
 
Advanced Windows Debugging
Advanced Windows DebuggingAdvanced Windows Debugging
Advanced Windows Debugging
 
Webinar Back to Basics 3 - Introduzione ai Replica Set
Webinar Back to Basics 3 - Introduzione ai Replica SetWebinar Back to Basics 3 - Introduzione ai Replica Set
Webinar Back to Basics 3 - Introduzione ai Replica Set
 
MongoDB: Optimising for Performance, Scale & Analytics
MongoDB: Optimising for Performance, Scale & AnalyticsMongoDB: Optimising for Performance, Scale & Analytics
MongoDB: Optimising for Performance, Scale & Analytics
 
Playing CTFs for Fun & Profit
Playing CTFs for Fun & ProfitPlaying CTFs for Fun & Profit
Playing CTFs for Fun & Profit
 
MongoDB Best Practices in AWS
MongoDB Best Practices in AWS MongoDB Best Practices in AWS
MongoDB Best Practices in AWS
 

More from MongoDB

MongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
MongoDB SoCal 2020: Migrate Anything* to MongoDB AtlasMongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
MongoDB SoCal 2020: Migrate Anything* to MongoDB AtlasMongoDB
 
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!MongoDB
 
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...MongoDB
 
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDBMongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDBMongoDB
 
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...MongoDB
 
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series DataMongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series DataMongoDB
 
MongoDB SoCal 2020: MongoDB Atlas Jump Start
 MongoDB SoCal 2020: MongoDB Atlas Jump Start MongoDB SoCal 2020: MongoDB Atlas Jump Start
MongoDB SoCal 2020: MongoDB Atlas Jump StartMongoDB
 
MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]
MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]
MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]MongoDB
 
MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2
MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2
MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2MongoDB
 
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...MongoDB
 
MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!
MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!
MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!MongoDB
 
MongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your Mindset
MongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your MindsetMongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your Mindset
MongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your MindsetMongoDB
 
MongoDB .local San Francisco 2020: MongoDB Atlas Jumpstart
MongoDB .local San Francisco 2020: MongoDB Atlas JumpstartMongoDB .local San Francisco 2020: MongoDB Atlas Jumpstart
MongoDB .local San Francisco 2020: MongoDB Atlas JumpstartMongoDB
 
MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...
MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...
MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...MongoDB
 
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++MongoDB .local San Francisco 2020: Aggregation Pipeline Power++
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++MongoDB
 
MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...
MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...
MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...MongoDB
 
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep Dive
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep DiveMongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep Dive
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep DiveMongoDB
 
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & Golang
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & GolangMongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & Golang
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & GolangMongoDB
 
MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...
MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...
MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...MongoDB
 
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...MongoDB
 

More from MongoDB (20)

MongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
MongoDB SoCal 2020: Migrate Anything* to MongoDB AtlasMongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
MongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
 
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!
 
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
 
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDBMongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB
 
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...
 
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series DataMongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data
 
MongoDB SoCal 2020: MongoDB Atlas Jump Start
 MongoDB SoCal 2020: MongoDB Atlas Jump Start MongoDB SoCal 2020: MongoDB Atlas Jump Start
MongoDB SoCal 2020: MongoDB Atlas Jump Start
 
MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]
MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]
MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]
 
MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2
MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2
MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2
 
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...
 
MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!
MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!
MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!
 
MongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your Mindset
MongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your MindsetMongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your Mindset
MongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your Mindset
 
MongoDB .local San Francisco 2020: MongoDB Atlas Jumpstart
MongoDB .local San Francisco 2020: MongoDB Atlas JumpstartMongoDB .local San Francisco 2020: MongoDB Atlas Jumpstart
MongoDB .local San Francisco 2020: MongoDB Atlas Jumpstart
 
MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...
MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...
MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...
 
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++MongoDB .local San Francisco 2020: Aggregation Pipeline Power++
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++
 
MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...
MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...
MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...
 
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep Dive
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep DiveMongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep Dive
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep Dive
 
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & Golang
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & GolangMongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & Golang
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & Golang
 
MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...
MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...
MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...
 
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...
 

Replication and Replica Sets

  • 1. #MongoDBTokyo Replication and Replica Sets Steve Francia Chief Evangelist, 10gen
  • 2. Agenda •  Replica Sets Lifecycle •  Developing with Replica Sets •  Operational Considerations •  Behind the Curtain
  • 3. Why Replication? •  How many have faced node failures? •  How many have been woken up from sleep to do a fail-over(s)? •  How many have experienced issues due to network latency? •  Different uses for data –  Normal processing –  Simple analytics
  • 5. Node 1 Node 2 Node 3 Replica Set – Creation
  • 6. Node 1 Node 2 Secondary Secondary Heartbeat Re n tio pli ica cat pl on i Re Node 3 Primary Replica Set – Initialize
  • 7. Primary Election Node 1 Node 2 Secondary Heartbeat Secondary Node 3 Replica Set – Failure
  • 8. Replication Node 1 Node 2 Secondary Primary Heartbeat Node 3 Replica Set – Failover
  • 9. Replication Node 1 Node 2 Secondary Primary Heartbeat n tio ica pl Re Node 3 Recovery Replica Set – Recovery
  • 10. Replication Node 1 Node 2 Secondary Primary Heartbeat n tio ica pl Re Node 3 Secondary Replica Set – Recovered
  • 12. Node 1 Node 2 Secondary Arbiter Heartbeat Re pli cat on i Node 3 Primary Replica Set Roles
  • 13. Configuration Options > conf = { _id : "mySet", members : [ {_id : 0, host : "A”, priority : 3}, {_id : 1, host : "B", priority : 2}, {_id : 2, host : "C”}, {_id : 3, host : "D", hidden : true}, {_id : 4, host : "E", hidden : true, slaveDelay : 3600} ] } > rs.initiate(conf)
  • 14. Configuration Options > conf = { _id : "mySet”, members : [ Primary DC {_id : 0, host : "A”, priority : 3}, {_id : 1, host : "B", priority : 2}, {_id : 2, host : "C”}, {_id : 3, host : "D", hidden : true}, {_id : 4, host : "E", hidden : true, slaveDelay : 3600} ] } > rs.initiate(conf)
  • 15. Configuration Options > conf = { Secondary DC _id : "mySet”, Default Priority = 1 members : [ {_id : 0, host : "A”, priority : 3}, {_id : 1, host : "B", priority : 2}, {_id : 2, host : "C”}, {_id : 3, host : "D", hidden : true}, {_id : 4, host : "E", hidden : true, slaveDelay : 3600} ] } > rs.initiate(conf)
  • 16. Configuration Options > conf = { _id : "mySet”, members : [ {_id : 0, host : "A”, priority : 3}, Analytics {_id : 1, host : "B", priority : 2}, node {_id : 2, host : "C”}, {_id : 3, host : "D", hidden : true}, {_id : 4, host : "E", hidden : true, slaveDelay : 3600} ] } > rs.initiate(conf)
  • 17. Configuration Options > conf = { _id : "mySet”, members : [ {_id : 0, host : "A”, priority : 3}, {_id : 1, host : "B", priority : 2}, {_id : 2, host : "C”}, {_id : 3, host : "D", hidden : true}, {_id : 4, host : "E", hidden : true, slaveDelay : 3600} ] } Backup node > rs.initiate(conf)
  • 19. Client Application Driver Write Read Primary Secondary Secondary Strong Consistency
  • 20. Client Application Driver Write ad Re Re ad Primary Secondary Secondary Delayed Consistency
  • 21. Write Concern •  Network acknowledgement •  Wait for error •  Wait for journal sync •  Wait for replication
  • 22. Driver write Primary apply in memory Unacknowledged
  • 23. Driver getLastError Primary apply in memory MongoDB Acknowledged (wait for error)
  • 24. Driver getLastError j:true write Primary apply in write to memory journal Wait for Journal Sync
  • 25. Driver getLastError write w:2 Primary replicate apply in memory Secondary Wait for Replication
  • 26. Tagging •  New in 2.0.0 •  Control where data is written to, and read from •  Each member can have one or more tags –  tags: {dc: "ny"} –  tags: {dc: "ny", subnet: "192.168", rack: "row3rk7"} •  Replica set defines rules for write concerns •  Rules can change without changing app code
  • 27. Tagging Example { _id : "mySet", members : [ {_id : 0, host : "A", tags : {"dc": "ny"}}, {_id : 1, host : "B", tags : {"dc": "ny"}}, {_id : 2, host : "C", tags : {"dc": "sf"}}, {_id : 3, host : "D", tags : {"dc": "sf"}}, {_id : 4, host : "E", tags : {"dc": "cloud"}}], settings : { getLastErrorModes : { allDCs : {"dc" : 3}, someDCs : {"dc" : 2}} } } > db.blogs.insert({...}) > db.runCommand({getLastError : 1, w : "someDCs"})
  • 28. Driver getLastError W:allDCs write Primary (SF) replicate apply in memory Secondary (NY) replicate Secondary (Cloud) Wait for Replication (Tagging)
  • 29. Read Preference Modes •  5 modes (new in 2.2) –  primary (only) - Default –  primaryPreferred –  secondary –  secondaryPreferred –  Nearest When more than one node is possible, closest node is used for reads (all modes but primary)
  • 30. Tagged Read Preference •  Custom read preferences •  Control where you read from by (node) tags –  E.g. { "disk": "ssd", "use": "reporting" } •  Use in conjunction with standard read preferences –  Except primary
  • 32. Maintenance and Upgrade •  No downtime •  Rolling upgrade/maintenance –  Start with Secondary –  Primary last
  • 33. Replica Set – 1 Data Center •  Single datacenter Datacenter •  Single switch & power Member 1 •  Points of failure: –  Power Member 2 –  Network –  Data center Datacenter 2 Member 3 –  Two node failure •  Automatic recovery of single node crash
  • 34. Replica Set – 2 Data Centers •  Multi data center Datacenter 1 •  DR node for safety Member 1 •  Can’t do multi data Member 2 center durable write safely since only 1 node in distant DC Datacenter 2 Member 3
  • 35. Replica Set – 3 Data Centers Datacenter 1 •  Three data centers Member 1 Member 2 •  Can survive full data center loss Datacenter 2 Member 3 •  Can do w= { dc : 2 } to Member 4 guarantee write in 2 data centers (with tags) Datacenter 3 Member 5
  • 36. Just Use It •  Use replica sets •  Easy to setup –  Try on a single machine •  Check doc page for RS tutorials –  http://docs.mongodb.org/manual/replication/#tutorials