SlideShare a Scribd company logo
Solutions Architect, 10gen
Marc Schwering
#MongoDBDays - @m4rcsch
Replication and Replica
Sets
Agenda
• Replica Sets Lifecycle
• Developing with Replica Sets
• Operational Considerations
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
Replica Set – Creation
Replica Set – Initialize
Replica Set – Failure
Replica Set – Failover
Replica Set – Recovery
Replica Set – Recovered
ReplicaSet Roles &
Configuration
Replica Set Roles
> 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 : [
{_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
Primary DC
> 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
Secondary DC
Default Priority = 1
> 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
Analytics
node
> 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
Backup node
Developing with Replica
Sets
Strong Consistency
Delayed Consistency
Write Concern
• Network acknowledgement
• Wait for error
• Wait for journal sync
• Wait for replication
Unacknowledged
MongoDB Acknowledged (wait for
error)
Wait for Journal Sync
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
{
_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"})
Tagging Example
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
• Single switch & power
• Points of failure:
– Power
– Network
– Data center
– Two node failure
• Automatic recovery of
single node crash
Replica Set – 2 Data Centers
• Multi data center
• DR node for safety
• Can’t do multi data
center durable write
safely since only 1
node in distant DC
Replica Set – 3 Data Centers
• Three data centers
• Can survive full data
center loss
• Can do w= { dc : 2 } to
guarantee write in 2
data centers (with tags)
Recent improvements
• Read preference support with sharding
– Drivers too
• Improved replication over WAN/high-latency
networks
• rs.syncFrom command
• buildIndexes setting
• replIndexPrefetch setting
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
Solutions Architect, 10gen
Marc Schwering
#MongoDBDays - @m4rcsch
Thank You

More Related Content

PPTX
Webinar: Replication and Replica Sets
PPTX
Replication and Replica Sets
PPTX
Replication and Replica Sets
PDF
Replication MongoDB Days 2013
PDF
Replication
PPTX
Replication and replica sets
PDF
2013 london advanced-replication
PDF
MongoDB Database Replication
Webinar: Replication and Replica Sets
Replication and Replica Sets
Replication and Replica Sets
Replication MongoDB Days 2013
Replication
Replication and replica sets
2013 london advanced-replication
MongoDB Database Replication

What's hot (19)

PPT
Replica Sets (NYC NoSQL Meetup)
PPTX
Advanced Replication
PDF
Robert Bernier - Recovering From A Damaged PostgreSQL Cluster @ Postgres Open
PDF
ClickHouse Unleashed 2020: Our Favorite New Features for Your Analytical Appl...
PDF
Javantura v2 - Replication with MongoDB - what could go wrong... - Philipp Krenn
PDF
Percona Live 4/15/15: Transparent sharding database virtualization engine (DVE)
PDF
Mongodb replication
PDF
ROracle
PDF
Mongodb workshop
PPTX
Replication and Replica Sets
PDF
Modern query optimisation features in MySQL 8.
PDF
groovy databases
PDF
Page cache in Linux kernel
PDF
Linux Kernel - Virtual File System
PPT
Python advanced 3.the python std lib by example – system related modules
PPTX
2016 03 15_biological_databases_part4
PDF
Cassandra Community Webinar | Introduction to Apache Cassandra 1.2
PDF
Using Apache Spark and MySQL for Data Analysis
PPTX
Hazelcast
Replica Sets (NYC NoSQL Meetup)
Advanced Replication
Robert Bernier - Recovering From A Damaged PostgreSQL Cluster @ Postgres Open
ClickHouse Unleashed 2020: Our Favorite New Features for Your Analytical Appl...
Javantura v2 - Replication with MongoDB - what could go wrong... - Philipp Krenn
Percona Live 4/15/15: Transparent sharding database virtualization engine (DVE)
Mongodb replication
ROracle
Mongodb workshop
Replication and Replica Sets
Modern query optimisation features in MySQL 8.
groovy databases
Page cache in Linux kernel
Linux Kernel - Virtual File System
Python advanced 3.the python std lib by example – system related modules
2016 03 15_biological_databases_part4
Cassandra Community Webinar | Introduction to Apache Cassandra 1.2
Using Apache Spark and MySQL for Data Analysis
Hazelcast
Ad

Similar to MongoDB London 2013: Basic Replication in MongoDB presented by Marc Schwering, 10gen (20)

PPTX
Basic Replication in MongoDB
PPTX
Webinar: Replication and Replica Sets
PDF
NoSQL Infrastructure
PDF
Replication and Replica Sets
PDF
The powerful toolset of the go-mysql library
PPTX
MongoDB for Time Series Data Part 3: Sharding
PDF
OSDC 2012 | Scaling with MongoDB by Ross Lawley
PDF
Scaling Databases with DBIx::Router
PPTX
Ops Jumpstart: MongoDB Administration 101
PDF
NoSQL Infrastructure - Late 2013
PPT
MongoDB Replica Sets
PDF
MongoDB: Optimising for Performance, Scale & Analytics
PPTX
Replication and Replica Sets
PDF
Rihards Olups - Zabbix 3.0: Excited for new features?
PDF
TrinityCore server install guide
PDF
MariaDB, MySQL and Ansible: automating database infrastructures
PDF
Scylla Summit 2022: ScyllaDB Rust Driver: One Driver to Rule Them All
PDF
Building node.js applications with Database Jones
PPTX
2015 02-09 - NoSQL Vorlesung Mosbach
KEY
Tek tutorial
Basic Replication in MongoDB
Webinar: Replication and Replica Sets
NoSQL Infrastructure
Replication and Replica Sets
The powerful toolset of the go-mysql library
MongoDB for Time Series Data Part 3: Sharding
OSDC 2012 | Scaling with MongoDB by Ross Lawley
Scaling Databases with DBIx::Router
Ops Jumpstart: MongoDB Administration 101
NoSQL Infrastructure - Late 2013
MongoDB Replica Sets
MongoDB: Optimising for Performance, Scale & Analytics
Replication and Replica Sets
Rihards Olups - Zabbix 3.0: Excited for new features?
TrinityCore server install guide
MariaDB, MySQL and Ansible: automating database infrastructures
Scylla Summit 2022: ScyllaDB Rust Driver: One Driver to Rule Them All
Building node.js applications with Database Jones
2015 02-09 - NoSQL Vorlesung Mosbach
Tek tutorial
Ad

More from MongoDB (20)

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

Recently uploaded (20)

PDF
IFRS Notes in your pocket for study all the time
PPTX
job Avenue by vinith.pptxvnbvnvnvbnvbnbmnbmbh
PDF
How to Get Funding for Your Trucking Business
PPT
Data mining for business intelligence ch04 sharda
PDF
DOC-20250806-WA0002._20250806_112011_0000.pdf
DOCX
Business Management - unit 1 and 2
PDF
COST SHEET- Tender and Quotation unit 2.pdf
PDF
Chapter 5_Foreign Exchange Market in .pdf
PDF
Laughter Yoga Basic Learning Workshop Manual
PPTX
Lecture (1)-Introduction.pptx business communication
DOCX
unit 1 COST ACCOUNTING AND COST SHEET
PPTX
Belch_12e_PPT_Ch18_Accessible_university.pptx
PPTX
The Marketing Journey - Tracey Phillips - Marketing Matters 7-2025.pptx
PDF
Training And Development of Employee .pdf
PDF
Solara Labs: Empowering Health through Innovative Nutraceutical Solutions
PPT
340036916-American-Literature-Literary-Period-Overview.ppt
PDF
Stem Cell Market Report | Trends, Growth & Forecast 2025-2034
PPTX
CkgxkgxydkydyldylydlydyldlyddolydyoyyU2.pptx
PPTX
Amazon (Business Studies) management studies
PDF
A Brief Introduction About Julia Allison
IFRS Notes in your pocket for study all the time
job Avenue by vinith.pptxvnbvnvnvbnvbnbmnbmbh
How to Get Funding for Your Trucking Business
Data mining for business intelligence ch04 sharda
DOC-20250806-WA0002._20250806_112011_0000.pdf
Business Management - unit 1 and 2
COST SHEET- Tender and Quotation unit 2.pdf
Chapter 5_Foreign Exchange Market in .pdf
Laughter Yoga Basic Learning Workshop Manual
Lecture (1)-Introduction.pptx business communication
unit 1 COST ACCOUNTING AND COST SHEET
Belch_12e_PPT_Ch18_Accessible_university.pptx
The Marketing Journey - Tracey Phillips - Marketing Matters 7-2025.pptx
Training And Development of Employee .pdf
Solara Labs: Empowering Health through Innovative Nutraceutical Solutions
340036916-American-Literature-Literary-Period-Overview.ppt
Stem Cell Market Report | Trends, Growth & Forecast 2025-2034
CkgxkgxydkydyldylydlydyldlyddolydyoyyU2.pptx
Amazon (Business Studies) management studies
A Brief Introduction About Julia Allison

MongoDB London 2013: Basic Replication in MongoDB presented by Marc Schwering, 10gen

  • 1. Solutions Architect, 10gen Marc Schwering #MongoDBDays - @m4rcsch Replication and Replica Sets
  • 2. Agenda • Replica Sets Lifecycle • Developing with Replica Sets • Operational Considerations
  • 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. Replica Set – Creation
  • 6. Replica Set – Initialize
  • 7. Replica Set – Failure
  • 8. Replica Set – Failover
  • 9. Replica Set – Recovery
  • 10. Replica Set – Recovered
  • 13. > 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
  • 14. > 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 Primary DC
  • 15. > 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 Secondary DC Default Priority = 1
  • 16. > 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 Analytics node
  • 17. > 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 Backup node
  • 21. Write Concern • Network acknowledgement • Wait for error • Wait for journal sync • 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. { _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"}) Tagging Example
  • 28. 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 • Single switch & power • Points of failure: – Power – Network – Data center – Two node failure • Automatic recovery of single node crash
  • 34. Replica Set – 2 Data Centers • Multi data center • DR node for safety • Can’t do multi data center durable write safely since only 1 node in distant DC
  • 35. Replica Set – 3 Data Centers • Three data centers • Can survive full data center loss • Can do w= { dc : 2 } to guarantee write in 2 data centers (with tags)
  • 36. Recent improvements • Read preference support with sharding – Drivers too • Improved replication over WAN/high-latency networks • rs.syncFrom command • buildIndexes setting • replIndexPrefetch setting
  • 37. 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
  • 38. Solutions Architect, 10gen Marc Schwering #MongoDBDays - @m4rcsch Thank You

Editor's Notes

  • #7: Basic explanation2 or more nodes form the setQuorum
  • #8: Initialize -> ElectionPrimary + data replication from primary to secondary
  • #9: Primary down/network failureAutomatic election of new primary if majority exists
  • #10: New primary electedReplication established from new primary
  • #11: Down node comes upRejoins setsRecovery and then secondary
  • #14: PrimaryData memberSecondaryHot standbyArbitersVoting member
  • #15: PriorityFloating point number between 0..1000Highest member that is up to date wins Up to date == within 10 seconds of primaryIf a higher priority member catches up, it will force election and win Slave DelayLags behind master by configurable time delay Automatically hidden from clientsProtects against operator errorsFat fingeringApplication corrupts data
  • #16: PriorityFloating point number between 0..1000Highest member that is up to date wins Up to date == within 10 seconds of primaryIf a higher priority member catches up, it will force election and win Slave DelayLags behind master by configurable time delay Automatically hidden from clientsProtects against operator errorsFat fingeringApplication corrupts data
  • #17: PriorityFloating point number between 0..1000Highest member that is up to date wins Up to date == within 10 seconds of primaryIf a higher priority member catches up, it will force election and win Slave DelayLags behind master by configurable time delay Automatically hidden from clientsProtects against operator errorsFat fingeringApplication corrupts data
  • #18: Analytics good for integrations with Hadoop, Storm, etc.
  • #19: PriorityFloating point number between 0..1000Highest member that is up to date wins Up to date == within 10 seconds of primaryIf a higher priority member catches up, it will force election and win Slave DelayLags behind master by configurable time delay Automatically hidden from clientsProtects against operator errorsFat fingeringApplication corrupts data
  • #20: ConsistencyWrite preferencesRead preferences
  • #24: Not really fire and forget. This return arrow is to confirm that the network successfully transferred the packet(s) of data.This confirms that the TCP ACK response was received.
  • #27: Presenter should mention:Default is w:1w:majority is what most people should use for durability. Majority is a special token here signifying more than half of the nodes in the set have acknowledged the write.
  • #29: Using 'someDCs' so that in the event of an outage, at least a majority of the DCs would receive the change. This favors availability over durability.
  • #30: Using 'allDCs' because we want to make certain all DCs have this piece of data. If any of the DCs are down, this would timeout. This favors durability over availability.
  • #33: Upgrade/maintenanceCommon deployment scenarios
  • #37: A good question to ask the audience : 'Why wouldn't you set w={dc:3}'… Why would you ever do that? What would be the complications?
  • #38: Schemaoplog
  • #42: rs.syncFromallows administrators to configure the member of a replica set that the current member will pull data from. Specify the name of the member you want to sync from in the form of [hostname]:[port].Replica Set Members will not Sync from Members Without Indexes Unless buildIndexes: falseTo prevent inconsistency between members of replica sets, if the member of a replica set has members[n].buildIndexes set to true, other members of the replica set will not sync from this member, unless they also have members[n].buildIndexes set to true. See SERVER-4160 for more information.New Option To Configure Index Pre-Fetching during ReplicationBy default, when replicating options, secondaries will pre-fetch Indexes associated with a query to improve replication throughput in most cases. The replIndexPrefetch setting and --replIndexPrefetch option allow administrators to disable this feature or allow the mongod to pre-fetch only the index on the _id field. See SERVER-6718 for more information.