SlideShare a Scribd company logo
1 of 31
Download to read offline
Apr-26-2017
Exploring the replication
and sharding in MongoDB
• Master degree, Software Engineering
• Working with databases since 2007
• MySQL, LAMP, Linux since 2010
• Pythian OSDB managed services since 2014
• Lead Database Consultant since 2016
• C100DBA: MongoDB certified DBA
https://mk.linkedin.com/in/igorle @igorLE
About me
© 2017 Pythian. Confidential
Overview
• What is replica set, how replication works, replication concepts
• Replica set features, deployment architectures
• Vertical vs Horizontal scaling
• What is a sharded cluster in MongoDB
• Cluster components - shards, config servers, mongos
• Shard keys and chunks
• Hashed vs range based sharding
• QA
© 2017 Pythian. Confidential
Replication
• Group of mongod processes that maintain the same data set
• Redundancy and high availability
• Increased read capacity
© 2017 Pythian. Confidential
Replication concept
1. Write operations go to the Primary node
2. All changes are recorded into operations log
3. Asynchronous replication to Secondary
4. Secondaries copy the Primary oplog
5. Secondary can use sync source Secondary*
Automatic failover on Primary failure
*settings.chainingAllowed (true by default)
© 2017 Pythian. Confidential
2. oplog
1.
3. 3.
4. 4.
5.
Replica set oplog
• Special capped collection that keeps a rolling record of all
operations that modify the data stored in the databases
• Idempotent
• Default oplog size
For Unix and Windows systems
Storage Engine Default Oplog Size Lower Bound Upper Bound
In-memory 5% of physical memory 50MB 50GB
WiredTiger 5% of free disk space 990MB 50GB
MMAPv1 5% of free disk space 990MB 50GB
© 2017 Pythian. Confidential
● Start each server with config options for replSet
/usr/bin/mongod --replSet "myRepl"
● Initiate the replica set on one node - rs.initialize()
● Verify the configuration - rs.conf()
Deployment
© 2017 Pythian. Confidential
Node 2 Node 3
rs.initialize() Node 1
• Add the rest of the nodes - rs.add() on the Primary node
rs.add(“node2:27017”) , rs.add(“node3:27017”)
• Check the status of the replica set - rs.status()
Deployment
© 2017 Pythian. Confidential
Node 2 Node 3
rs.add()
Configuration options
• 50 members per replica set (7 voting members)
• Arbiter node
• Priority 0 node
• Hidden node
• Delayed node
• Write concern
• Read preference
© 2017 Pythian. Confidential
Arbiter node
• Does not hold copy of data
• Votes in elections
hidden : true
© 2017 Pythian. Confidential
Arbiter
Priority 0 node
Priority - floating point (i.e. decimal) number between 0 and 1000
• Never becomes primary
• Visible to application
• Node with highest priority is eventually elected as Primary
© 2017 Pythian. Confidential
Secondary
priority : 0
Hidden node
• Never becomes primary
• Not visible to application
• Use cases
○ reporting
○ backups
hidden : true
© 2017 Pythian. Confidential
hidden: true priority:0
Secondary
hidden : true priority : 0
Delayed node
• Must be priority 0 member
• Should be hidden member (not mandatory)
• Has votes 1 by default
• Considerations (oplog size)
• Mainly used for backups
© 2017 Pythian. Confidential
Secondary
slaveDelay : 3600
priority : 0
hidden : true
Write concern
{ w: <value>, j: <boolean>, wtimeout: <number> }
● w - number of mongod instances that
acknowledged the write operation
● j - acknowledgement that the write operation
has been written to the journal
● wtimeout - time limit to prevent write operations
from blocking indefinitely
© 2017 Pythian. Confidential
Read preference
How read operations are routed to replica set members
1. primary (by default)
2. primaryPreferred
3. secondary
4. secondaryPreferred
5. nearest (least network latency)
MongoDB 3.4 maxStalenessSeconds ( >= 90 seconds)
© 2017 Pythian. Confidential
Driver
1.
2. 2.
2.
3. 3.4.4.
4.
5. 5.
5.
• CPU
• RAM
• DISK
Scaling (vertical)
© 2017 Pythian. Confidential
• Method for distributing data across multiple machines
• Splitting data across multiple horizontal partitions
Scaling (horizontal) - Sharding
© 2017 Pythian. Confidential
Sharding with MongoDB
Shard
© 2017 Pythian. Confidential
Shard
Data
Sharding with MongoDB
• Shard/Replica set
(subset of the sharded data)
• Config servers
(metadata and config settings)
• mongos
(query router, cluster interface)
© 2017 Pythian. Confidential
Shard
Data
Sharding with MongoDB
• Shard/Replica set
(subset of the sharded data)
• Config servers
(metadata and config settings)
• mongos
(query router, cluster interface)
sh.addShard("shardName")
© 2017 Pythian. Confidential
A B
Shards
• Contains subset of sharded data
• Replica set for redundancy and HA
• Primary shard
• Non sharded collections
• --shardsvr in config file (port 27018)
© 2017 Pythian. Confidential
Config servers
• Config servers as replica set only (>= 3.4)
• Stores the metadata for sharded cluster in
config database
• Authentication configuration information in
admin database
• Holds balancer on Primary node (>= 3.4)
• --configsvr in config file (port 27019)
© 2017 Pythian. Confidential
mongos
• Caching metadata from config servers
• Routes queries to shards
• No persistent state
• Updates cache on metadata changes
• Holds balancer (mongodb <= 3.2)
• mongos version 3.4 can not connect to
earlier mongod version
© 2017 Pythian. Confidential
Sharding collection
• Enable sharding on database
sh.enableSharding("users")
• Shard collection
sh.shardCollection("users.history", { user_id : 1 } )
• Shard key - indexed key that exists in every document
○ range based
sh.shardCollection("users.history", { user_id : 1 } )
○ hashed based
sh.shardCollection( "users.history", { user_id : "hashed" } )
© 2017 Pythian. Confidential
Shard keys and chunks
Choosing Shard key
• Large Shard Key Cardinality
• Low Shard Key Frequency
• Non-Monotonically changing shard keys
Chunks
• A contiguous range of shard key values within a particular shard
• Inclusive lower and exclusive upper range based on shard key
• Default size of 64MB
© 2017 Pythian. Confidential
Ranged sharding
• Dividing data into contiguous ranges determined by the shard key values
• Documents with “close” shard key values are likely to be in the same
chunk or shard
• Query Isolation - more likely to target single shard
© 2017 Pythian. Confidential
Hashed sharding
• Uses a hashed index of a single field as the shard key to partition data
• More even data distribution at the cost of reducing Query Isolation
• Applications do not need to compute hashes
• Keys that change monotonically like ObjectId or timestamps are ideal
© 2017 Pythian. Confidential
Shard keys limitations
• Must be ascending indexed key or indexed compound keys that
exists in every document in the collection
• Cannot be multikey index, a text index or a geospatial index
• Cannot exceed 512 bytes
• Immutable key - can not be updated/changed
• Update operations that affect a single document must include the
shard key or the _id field
• No option for sharding if unique indexes on other fields exist
• No option for second unique index if the shard key is unique index
© 2017 Pythian. Confidential
Summary
• Replica set with odd number of voting members
• Hidden or Delayed member for dedicated functions (backups …)
• Dataset fits into single server, keep unsharded deployment
• Horizontal scaling - shards running as replica sets
• Shard keys are immutable with max size of 512 bytes
• Shard keys must exists in every document in the collection
• Ranged sharding may not distribute the data evenly
• Hashed sharding distributes the data randomly
© 2017 Pythian. Confidential
Questions?
© 2017 Pythian. Confidential
We’re Hiring!
https://www.pythian.com/careers/
© 2017 Pythian. Confidential

More Related Content

What's hot

SS7: Locate. Track. Manipulate.
SS7: Locate. Track. Manipulate.SS7: Locate. Track. Manipulate.
SS7: Locate. Track. Manipulate.3G4G
 
Socket programming
Socket programmingSocket programming
Socket programmingAnurag Tomar
 
Kamailio :: A Quick Introduction
Kamailio :: A Quick IntroductionKamailio :: A Quick Introduction
Kamailio :: A Quick IntroductionOlle E Johansson
 
Deepu Kumar Shah.pptx
Deepu Kumar Shah.pptxDeepu Kumar Shah.pptx
Deepu Kumar Shah.pptxDeepuShah
 
Настройка резервирования в Mikrotik. Dual-WAN, основные принципы и пошаговая ...
Настройка резервирования в Mikrotik. Dual-WAN, основные принципы и пошаговая ...Настройка резервирования в Mikrotik. Dual-WAN, основные принципы и пошаговая ...
Настройка резервирования в Mikrotik. Dual-WAN, основные принципы и пошаговая ...mikrotik-training
 
MySQL Cluster Scaling to a Billion Queries
MySQL Cluster Scaling to a Billion QueriesMySQL Cluster Scaling to a Billion Queries
MySQL Cluster Scaling to a Billion QueriesBernd Ocklin
 
Embedded TCP/IP stack for FreeRTOS
Embedded TCP/IP stack for FreeRTOSEmbedded TCP/IP stack for FreeRTOS
Embedded TCP/IP stack for FreeRTOS艾鍗科技
 
What Does ICANN Do (English)
What Does ICANN Do (English)What Does ICANN Do (English)
What Does ICANN Do (English)ICANN
 
Mobicents Summit 2012 - Vladimir Ralev - Mobicents Load Balancer and High Ava...
Mobicents Summit 2012 - Vladimir Ralev - Mobicents Load Balancer and High Ava...Mobicents Summit 2012 - Vladimir Ralev - Mobicents Load Balancer and High Ava...
Mobicents Summit 2012 - Vladimir Ralev - Mobicents Load Balancer and High Ava...telestax
 
Introduction to File System
Introduction to File SystemIntroduction to File System
Introduction to File SystemSanthiNivas
 
Hacking SIP Like a Boss!
Hacking SIP Like a Boss!Hacking SIP Like a Boss!
Hacking SIP Like a Boss!Fatih Ozavci
 

What's hot (20)

Network security
Network securityNetwork security
Network security
 
File systems for Embedded Linux
File systems for Embedded LinuxFile systems for Embedded Linux
File systems for Embedded Linux
 
SS7: Locate. Track. Manipulate.
SS7: Locate. Track. Manipulate.SS7: Locate. Track. Manipulate.
SS7: Locate. Track. Manipulate.
 
Socket programming
Socket programmingSocket programming
Socket programming
 
Kamailio :: A Quick Introduction
Kamailio :: A Quick IntroductionKamailio :: A Quick Introduction
Kamailio :: A Quick Introduction
 
Deepu Kumar Shah.pptx
Deepu Kumar Shah.pptxDeepu Kumar Shah.pptx
Deepu Kumar Shah.pptx
 
Настройка резервирования в Mikrotik. Dual-WAN, основные принципы и пошаговая ...
Настройка резервирования в Mikrotik. Dual-WAN, основные принципы и пошаговая ...Настройка резервирования в Mikrotik. Dual-WAN, основные принципы и пошаговая ...
Настройка резервирования в Mikrotik. Dual-WAN, основные принципы и пошаговая ...
 
MySQL Cluster Scaling to a Billion Queries
MySQL Cluster Scaling to a Billion QueriesMySQL Cluster Scaling to a Billion Queries
MySQL Cluster Scaling to a Billion Queries
 
IoT security zigbee -- Null Meet bangalore
IoT security zigbee -- Null Meet bangaloreIoT security zigbee -- Null Meet bangalore
IoT security zigbee -- Null Meet bangalore
 
ICMP
ICMP ICMP
ICMP
 
Windows Forensic 101
Windows Forensic 101Windows Forensic 101
Windows Forensic 101
 
Memory Forensics
Memory ForensicsMemory Forensics
Memory Forensics
 
Embedded TCP/IP stack for FreeRTOS
Embedded TCP/IP stack for FreeRTOSEmbedded TCP/IP stack for FreeRTOS
Embedded TCP/IP stack for FreeRTOS
 
What Does ICANN Do (English)
What Does ICANN Do (English)What Does ICANN Do (English)
What Does ICANN Do (English)
 
Mobicents Summit 2012 - Vladimir Ralev - Mobicents Load Balancer and High Ava...
Mobicents Summit 2012 - Vladimir Ralev - Mobicents Load Balancer and High Ava...Mobicents Summit 2012 - Vladimir Ralev - Mobicents Load Balancer and High Ava...
Mobicents Summit 2012 - Vladimir Ralev - Mobicents Load Balancer and High Ava...
 
RAT - Repurposing Adversarial Tradecraft
RAT - Repurposing Adversarial TradecraftRAT - Repurposing Adversarial Tradecraft
RAT - Repurposing Adversarial Tradecraft
 
OSI layer (Network)
OSI layer (Network)OSI layer (Network)
OSI layer (Network)
 
Introduction to File System
Introduction to File SystemIntroduction to File System
Introduction to File System
 
Hacking the swisscom modem
Hacking the swisscom modemHacking the swisscom modem
Hacking the swisscom modem
 
Hacking SIP Like a Boss!
Hacking SIP Like a Boss!Hacking SIP Like a Boss!
Hacking SIP Like a Boss!
 

Similar to Exploring the replication and sharding in MongoDB

MySQL Data Encryption at Rest
MySQL Data Encryption at RestMySQL Data Encryption at Rest
MySQL Data Encryption at RestMydbops
 
Data dictionary pl17
Data dictionary pl17Data dictionary pl17
Data dictionary pl17Ståle Deraas
 
MySQL :What's New #GIDS16
MySQL :What's New #GIDS16MySQL :What's New #GIDS16
MySQL :What's New #GIDS16Sanjay Manwani
 
MongoDB : Scaling, Security & Performance
MongoDB : Scaling, Security & PerformanceMongoDB : Scaling, Security & Performance
MongoDB : Scaling, Security & PerformanceSasidhar Gogulapati
 
Pimping the ForgeRock Identity Platform for a Billion Users
Pimping the ForgeRock Identity Platform for a Billion UsersPimping the ForgeRock Identity Platform for a Billion Users
Pimping the ForgeRock Identity Platform for a Billion UsersForgeRock
 
MariaDB Server Compatibility with MySQL
MariaDB Server Compatibility with MySQLMariaDB Server Compatibility with MySQL
MariaDB Server Compatibility with MySQLColin Charles
 
Spring data presentation
Spring data presentationSpring data presentation
Spring data presentationOleksii Usyk
 
MySQL Load Balancers - Maxscale, ProxySQL, HAProxy, MySQL Router & nginx - A ...
MySQL Load Balancers - Maxscale, ProxySQL, HAProxy, MySQL Router & nginx - A ...MySQL Load Balancers - Maxscale, ProxySQL, HAProxy, MySQL Router & nginx - A ...
MySQL Load Balancers - Maxscale, ProxySQL, HAProxy, MySQL Router & nginx - A ...Severalnines
 
Exploring the replication in MongoDB
Exploring the replication in MongoDBExploring the replication in MongoDB
Exploring the replication in MongoDBIgor Donchovski
 
Scaling-MongoDB-with-Horizontal-and-Vertical-Sharding Mydbops Opensource Data...
Scaling-MongoDB-with-Horizontal-and-Vertical-Sharding Mydbops Opensource Data...Scaling-MongoDB-with-Horizontal-and-Vertical-Sharding Mydbops Opensource Data...
Scaling-MongoDB-with-Horizontal-and-Vertical-Sharding Mydbops Opensource Data...Mydbops
 
Scaling MongoDB with Horizontal and Vertical Sharding
Scaling MongoDB with Horizontal and Vertical Sharding Scaling MongoDB with Horizontal and Vertical Sharding
Scaling MongoDB with Horizontal and Vertical Sharding Mydbops
 
Keeping your Enterprise’s Big Data Secure by Owen O’Malley at Big Data Spain ...
Keeping your Enterprise’s Big Data Secure by Owen O’Malley at Big Data Spain ...Keeping your Enterprise’s Big Data Secure by Owen O’Malley at Big Data Spain ...
Keeping your Enterprise’s Big Data Secure by Owen O’Malley at Big Data Spain ...Big Data Spain
 
Oracle big data appliance and solutions
Oracle big data appliance and solutionsOracle big data appliance and solutions
Oracle big data appliance and solutionssolarisyougood
 
Move your on prem data to a lake in a Lake in Cloud
Move your on prem data to a lake in a Lake in CloudMove your on prem data to a lake in a Lake in Cloud
Move your on prem data to a lake in a Lake in CloudCAMMS
 
Webinar - DreamObjects/Ceph Case Study
Webinar - DreamObjects/Ceph Case StudyWebinar - DreamObjects/Ceph Case Study
Webinar - DreamObjects/Ceph Case StudyCeph Community
 

Similar to Exploring the replication and sharding in MongoDB (20)

How to scale MongoDB
How to scale MongoDBHow to scale MongoDB
How to scale MongoDB
 
Introduction to Mongodb
Introduction to MongodbIntroduction to Mongodb
Introduction to Mongodb
 
Novinky v Oracle Database 18c
Novinky v Oracle Database 18cNovinky v Oracle Database 18c
Novinky v Oracle Database 18c
 
MySQL Data Encryption at Rest
MySQL Data Encryption at RestMySQL Data Encryption at Rest
MySQL Data Encryption at Rest
 
Data dictionary pl17
Data dictionary pl17Data dictionary pl17
Data dictionary pl17
 
MySQL :What's New #GIDS16
MySQL :What's New #GIDS16MySQL :What's New #GIDS16
MySQL :What's New #GIDS16
 
MongoDB : Scaling, Security & Performance
MongoDB : Scaling, Security & PerformanceMongoDB : Scaling, Security & Performance
MongoDB : Scaling, Security & Performance
 
Pimping the ForgeRock Identity Platform for a Billion Users
Pimping the ForgeRock Identity Platform for a Billion UsersPimping the ForgeRock Identity Platform for a Billion Users
Pimping the ForgeRock Identity Platform for a Billion Users
 
MariaDB Server Compatibility with MySQL
MariaDB Server Compatibility with MySQLMariaDB Server Compatibility with MySQL
MariaDB Server Compatibility with MySQL
 
Spring data presentation
Spring data presentationSpring data presentation
Spring data presentation
 
Mongo db 3.4 Overview
Mongo db 3.4 OverviewMongo db 3.4 Overview
Mongo db 3.4 Overview
 
MySQL Load Balancers - Maxscale, ProxySQL, HAProxy, MySQL Router & nginx - A ...
MySQL Load Balancers - Maxscale, ProxySQL, HAProxy, MySQL Router & nginx - A ...MySQL Load Balancers - Maxscale, ProxySQL, HAProxy, MySQL Router & nginx - A ...
MySQL Load Balancers - Maxscale, ProxySQL, HAProxy, MySQL Router & nginx - A ...
 
Hadoop
HadoopHadoop
Hadoop
 
Exploring the replication in MongoDB
Exploring the replication in MongoDBExploring the replication in MongoDB
Exploring the replication in MongoDB
 
Scaling-MongoDB-with-Horizontal-and-Vertical-Sharding Mydbops Opensource Data...
Scaling-MongoDB-with-Horizontal-and-Vertical-Sharding Mydbops Opensource Data...Scaling-MongoDB-with-Horizontal-and-Vertical-Sharding Mydbops Opensource Data...
Scaling-MongoDB-with-Horizontal-and-Vertical-Sharding Mydbops Opensource Data...
 
Scaling MongoDB with Horizontal and Vertical Sharding
Scaling MongoDB with Horizontal and Vertical Sharding Scaling MongoDB with Horizontal and Vertical Sharding
Scaling MongoDB with Horizontal and Vertical Sharding
 
Keeping your Enterprise’s Big Data Secure by Owen O’Malley at Big Data Spain ...
Keeping your Enterprise’s Big Data Secure by Owen O’Malley at Big Data Spain ...Keeping your Enterprise’s Big Data Secure by Owen O’Malley at Big Data Spain ...
Keeping your Enterprise’s Big Data Secure by Owen O’Malley at Big Data Spain ...
 
Oracle big data appliance and solutions
Oracle big data appliance and solutionsOracle big data appliance and solutions
Oracle big data appliance and solutions
 
Move your on prem data to a lake in a Lake in Cloud
Move your on prem data to a lake in a Lake in CloudMove your on prem data to a lake in a Lake in Cloud
Move your on prem data to a lake in a Lake in Cloud
 
Webinar - DreamObjects/Ceph Case Study
Webinar - DreamObjects/Ceph Case StudyWebinar - DreamObjects/Ceph Case Study
Webinar - DreamObjects/Ceph Case Study
 

More from Igor Donchovski

MongoDB Backups and PITR
MongoDB Backups and PITRMongoDB Backups and PITR
MongoDB Backups and PITRIgor Donchovski
 
Sharding and things we'd like to see improved
Sharding and things we'd like to see improvedSharding and things we'd like to see improved
Sharding and things we'd like to see improvedIgor Donchovski
 
Maintenance for MongoDB Replica Sets
Maintenance for MongoDB Replica SetsMaintenance for MongoDB Replica Sets
Maintenance for MongoDB Replica SetsIgor Donchovski
 
MongoDB HA - what can go wrong
MongoDB HA - what can go wrongMongoDB HA - what can go wrong
MongoDB HA - what can go wrongIgor Donchovski
 
Enhancing the default MongoDB Security
Enhancing the default MongoDB SecurityEnhancing the default MongoDB Security
Enhancing the default MongoDB SecurityIgor Donchovski
 
Working with MongoDB as MySQL DBA
Working with MongoDB as MySQL DBAWorking with MongoDB as MySQL DBA
Working with MongoDB as MySQL DBAIgor Donchovski
 

More from Igor Donchovski (6)

MongoDB Backups and PITR
MongoDB Backups and PITRMongoDB Backups and PITR
MongoDB Backups and PITR
 
Sharding and things we'd like to see improved
Sharding and things we'd like to see improvedSharding and things we'd like to see improved
Sharding and things we'd like to see improved
 
Maintenance for MongoDB Replica Sets
Maintenance for MongoDB Replica SetsMaintenance for MongoDB Replica Sets
Maintenance for MongoDB Replica Sets
 
MongoDB HA - what can go wrong
MongoDB HA - what can go wrongMongoDB HA - what can go wrong
MongoDB HA - what can go wrong
 
Enhancing the default MongoDB Security
Enhancing the default MongoDB SecurityEnhancing the default MongoDB Security
Enhancing the default MongoDB Security
 
Working with MongoDB as MySQL DBA
Working with MongoDB as MySQL DBAWorking with MongoDB as MySQL DBA
Working with MongoDB as MySQL DBA
 

Recently uploaded

THE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTION
THE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTIONTHE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTION
THE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTIONjhunlian
 
CME 397 - SURFACE ENGINEERING - UNIT 1 FULL NOTES
CME 397 - SURFACE ENGINEERING - UNIT 1 FULL NOTESCME 397 - SURFACE ENGINEERING - UNIT 1 FULL NOTES
CME 397 - SURFACE ENGINEERING - UNIT 1 FULL NOTESkarthi keyan
 
multiple access in wireless communication
multiple access in wireless communicationmultiple access in wireless communication
multiple access in wireless communicationpanditadesh123
 
Python Programming for basic beginners.pptx
Python Programming for basic beginners.pptxPython Programming for basic beginners.pptx
Python Programming for basic beginners.pptxmohitesoham12
 
Levelling - Rise and fall - Height of instrument method
Levelling - Rise and fall - Height of instrument methodLevelling - Rise and fall - Height of instrument method
Levelling - Rise and fall - Height of instrument methodManicka Mamallan Andavar
 
US Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of ActionUS Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of ActionMebane Rash
 
Prach: A Feature-Rich Platform Empowering the Autism Community
Prach: A Feature-Rich Platform Empowering the Autism CommunityPrach: A Feature-Rich Platform Empowering the Autism Community
Prach: A Feature-Rich Platform Empowering the Autism Communityprachaibot
 
Comparative study of High-rise Building Using ETABS,SAP200 and SAFE., SAFE an...
Comparative study of High-rise Building Using ETABS,SAP200 and SAFE., SAFE an...Comparative study of High-rise Building Using ETABS,SAP200 and SAFE., SAFE an...
Comparative study of High-rise Building Using ETABS,SAP200 and SAFE., SAFE an...Erbil Polytechnic University
 
Comprehensive energy systems.pdf Comprehensive energy systems.pdf
Comprehensive energy systems.pdf Comprehensive energy systems.pdfComprehensive energy systems.pdf Comprehensive energy systems.pdf
Comprehensive energy systems.pdf Comprehensive energy systems.pdfalene1
 
A brief look at visionOS - How to develop app on Apple's Vision Pro
A brief look at visionOS - How to develop app on Apple's Vision ProA brief look at visionOS - How to develop app on Apple's Vision Pro
A brief look at visionOS - How to develop app on Apple's Vision ProRay Yuan Liu
 
Javier_Fernandez_CARS_workshop_presentation.pptx
Javier_Fernandez_CARS_workshop_presentation.pptxJavier_Fernandez_CARS_workshop_presentation.pptx
Javier_Fernandez_CARS_workshop_presentation.pptxJavier Fernández Muñoz
 
Cost estimation approach: FP to COCOMO scenario based question
Cost estimation approach: FP to COCOMO scenario based questionCost estimation approach: FP to COCOMO scenario based question
Cost estimation approach: FP to COCOMO scenario based questionSneha Padhiar
 
priority interrupt computer organization
priority interrupt computer organizationpriority interrupt computer organization
priority interrupt computer organizationchnrketan
 
Forming section troubleshooting checklist for improving wire life (1).ppt
Forming section troubleshooting checklist for improving wire life (1).pptForming section troubleshooting checklist for improving wire life (1).ppt
Forming section troubleshooting checklist for improving wire life (1).pptNoman khan
 
Secure Key Crypto - Tech Paper JET Tech Labs
Secure Key Crypto - Tech Paper JET Tech LabsSecure Key Crypto - Tech Paper JET Tech Labs
Secure Key Crypto - Tech Paper JET Tech Labsamber724300
 
Robotics Group 10 (Control Schemes) cse.pdf
Robotics Group 10  (Control Schemes) cse.pdfRobotics Group 10  (Control Schemes) cse.pdf
Robotics Group 10 (Control Schemes) cse.pdfsahilsajad201
 
STATE TRANSITION DIAGRAM in psoc subject
STATE TRANSITION DIAGRAM in psoc subjectSTATE TRANSITION DIAGRAM in psoc subject
STATE TRANSITION DIAGRAM in psoc subjectGayathriM270621
 
Gravity concentration_MI20612MI_________
Gravity concentration_MI20612MI_________Gravity concentration_MI20612MI_________
Gravity concentration_MI20612MI_________Romil Mishra
 
Virtual memory management in Operating System
Virtual memory management in Operating SystemVirtual memory management in Operating System
Virtual memory management in Operating SystemRashmi Bhat
 
ROBOETHICS-CCS345 ETHICS AND ARTIFICIAL INTELLIGENCE.ppt
ROBOETHICS-CCS345 ETHICS AND ARTIFICIAL INTELLIGENCE.pptROBOETHICS-CCS345 ETHICS AND ARTIFICIAL INTELLIGENCE.ppt
ROBOETHICS-CCS345 ETHICS AND ARTIFICIAL INTELLIGENCE.pptJohnWilliam111370
 

Recently uploaded (20)

THE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTION
THE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTIONTHE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTION
THE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTION
 
CME 397 - SURFACE ENGINEERING - UNIT 1 FULL NOTES
CME 397 - SURFACE ENGINEERING - UNIT 1 FULL NOTESCME 397 - SURFACE ENGINEERING - UNIT 1 FULL NOTES
CME 397 - SURFACE ENGINEERING - UNIT 1 FULL NOTES
 
multiple access in wireless communication
multiple access in wireless communicationmultiple access in wireless communication
multiple access in wireless communication
 
Python Programming for basic beginners.pptx
Python Programming for basic beginners.pptxPython Programming for basic beginners.pptx
Python Programming for basic beginners.pptx
 
Levelling - Rise and fall - Height of instrument method
Levelling - Rise and fall - Height of instrument methodLevelling - Rise and fall - Height of instrument method
Levelling - Rise and fall - Height of instrument method
 
US Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of ActionUS Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of Action
 
Prach: A Feature-Rich Platform Empowering the Autism Community
Prach: A Feature-Rich Platform Empowering the Autism CommunityPrach: A Feature-Rich Platform Empowering the Autism Community
Prach: A Feature-Rich Platform Empowering the Autism Community
 
Comparative study of High-rise Building Using ETABS,SAP200 and SAFE., SAFE an...
Comparative study of High-rise Building Using ETABS,SAP200 and SAFE., SAFE an...Comparative study of High-rise Building Using ETABS,SAP200 and SAFE., SAFE an...
Comparative study of High-rise Building Using ETABS,SAP200 and SAFE., SAFE an...
 
Comprehensive energy systems.pdf Comprehensive energy systems.pdf
Comprehensive energy systems.pdf Comprehensive energy systems.pdfComprehensive energy systems.pdf Comprehensive energy systems.pdf
Comprehensive energy systems.pdf Comprehensive energy systems.pdf
 
A brief look at visionOS - How to develop app on Apple's Vision Pro
A brief look at visionOS - How to develop app on Apple's Vision ProA brief look at visionOS - How to develop app on Apple's Vision Pro
A brief look at visionOS - How to develop app on Apple's Vision Pro
 
Javier_Fernandez_CARS_workshop_presentation.pptx
Javier_Fernandez_CARS_workshop_presentation.pptxJavier_Fernandez_CARS_workshop_presentation.pptx
Javier_Fernandez_CARS_workshop_presentation.pptx
 
Cost estimation approach: FP to COCOMO scenario based question
Cost estimation approach: FP to COCOMO scenario based questionCost estimation approach: FP to COCOMO scenario based question
Cost estimation approach: FP to COCOMO scenario based question
 
priority interrupt computer organization
priority interrupt computer organizationpriority interrupt computer organization
priority interrupt computer organization
 
Forming section troubleshooting checklist for improving wire life (1).ppt
Forming section troubleshooting checklist for improving wire life (1).pptForming section troubleshooting checklist for improving wire life (1).ppt
Forming section troubleshooting checklist for improving wire life (1).ppt
 
Secure Key Crypto - Tech Paper JET Tech Labs
Secure Key Crypto - Tech Paper JET Tech LabsSecure Key Crypto - Tech Paper JET Tech Labs
Secure Key Crypto - Tech Paper JET Tech Labs
 
Robotics Group 10 (Control Schemes) cse.pdf
Robotics Group 10  (Control Schemes) cse.pdfRobotics Group 10  (Control Schemes) cse.pdf
Robotics Group 10 (Control Schemes) cse.pdf
 
STATE TRANSITION DIAGRAM in psoc subject
STATE TRANSITION DIAGRAM in psoc subjectSTATE TRANSITION DIAGRAM in psoc subject
STATE TRANSITION DIAGRAM in psoc subject
 
Gravity concentration_MI20612MI_________
Gravity concentration_MI20612MI_________Gravity concentration_MI20612MI_________
Gravity concentration_MI20612MI_________
 
Virtual memory management in Operating System
Virtual memory management in Operating SystemVirtual memory management in Operating System
Virtual memory management in Operating System
 
ROBOETHICS-CCS345 ETHICS AND ARTIFICIAL INTELLIGENCE.ppt
ROBOETHICS-CCS345 ETHICS AND ARTIFICIAL INTELLIGENCE.pptROBOETHICS-CCS345 ETHICS AND ARTIFICIAL INTELLIGENCE.ppt
ROBOETHICS-CCS345 ETHICS AND ARTIFICIAL INTELLIGENCE.ppt
 

Exploring the replication and sharding in MongoDB

  • 2. • Master degree, Software Engineering • Working with databases since 2007 • MySQL, LAMP, Linux since 2010 • Pythian OSDB managed services since 2014 • Lead Database Consultant since 2016 • C100DBA: MongoDB certified DBA https://mk.linkedin.com/in/igorle @igorLE About me © 2017 Pythian. Confidential
  • 3. Overview • What is replica set, how replication works, replication concepts • Replica set features, deployment architectures • Vertical vs Horizontal scaling • What is a sharded cluster in MongoDB • Cluster components - shards, config servers, mongos • Shard keys and chunks • Hashed vs range based sharding • QA © 2017 Pythian. Confidential
  • 4. Replication • Group of mongod processes that maintain the same data set • Redundancy and high availability • Increased read capacity © 2017 Pythian. Confidential
  • 5. Replication concept 1. Write operations go to the Primary node 2. All changes are recorded into operations log 3. Asynchronous replication to Secondary 4. Secondaries copy the Primary oplog 5. Secondary can use sync source Secondary* Automatic failover on Primary failure *settings.chainingAllowed (true by default) © 2017 Pythian. Confidential 2. oplog 1. 3. 3. 4. 4. 5.
  • 6. Replica set oplog • Special capped collection that keeps a rolling record of all operations that modify the data stored in the databases • Idempotent • Default oplog size For Unix and Windows systems Storage Engine Default Oplog Size Lower Bound Upper Bound In-memory 5% of physical memory 50MB 50GB WiredTiger 5% of free disk space 990MB 50GB MMAPv1 5% of free disk space 990MB 50GB © 2017 Pythian. Confidential
  • 7. ● Start each server with config options for replSet /usr/bin/mongod --replSet "myRepl" ● Initiate the replica set on one node - rs.initialize() ● Verify the configuration - rs.conf() Deployment © 2017 Pythian. Confidential Node 2 Node 3 rs.initialize() Node 1
  • 8. • Add the rest of the nodes - rs.add() on the Primary node rs.add(“node2:27017”) , rs.add(“node3:27017”) • Check the status of the replica set - rs.status() Deployment © 2017 Pythian. Confidential Node 2 Node 3 rs.add()
  • 9. Configuration options • 50 members per replica set (7 voting members) • Arbiter node • Priority 0 node • Hidden node • Delayed node • Write concern • Read preference © 2017 Pythian. Confidential
  • 10. Arbiter node • Does not hold copy of data • Votes in elections hidden : true © 2017 Pythian. Confidential Arbiter
  • 11. Priority 0 node Priority - floating point (i.e. decimal) number between 0 and 1000 • Never becomes primary • Visible to application • Node with highest priority is eventually elected as Primary © 2017 Pythian. Confidential Secondary priority : 0
  • 12. Hidden node • Never becomes primary • Not visible to application • Use cases ○ reporting ○ backups hidden : true © 2017 Pythian. Confidential hidden: true priority:0 Secondary hidden : true priority : 0
  • 13. Delayed node • Must be priority 0 member • Should be hidden member (not mandatory) • Has votes 1 by default • Considerations (oplog size) • Mainly used for backups © 2017 Pythian. Confidential Secondary slaveDelay : 3600 priority : 0 hidden : true
  • 14. Write concern { w: <value>, j: <boolean>, wtimeout: <number> } ● w - number of mongod instances that acknowledged the write operation ● j - acknowledgement that the write operation has been written to the journal ● wtimeout - time limit to prevent write operations from blocking indefinitely © 2017 Pythian. Confidential
  • 15. Read preference How read operations are routed to replica set members 1. primary (by default) 2. primaryPreferred 3. secondary 4. secondaryPreferred 5. nearest (least network latency) MongoDB 3.4 maxStalenessSeconds ( >= 90 seconds) © 2017 Pythian. Confidential Driver 1. 2. 2. 2. 3. 3.4.4. 4. 5. 5. 5.
  • 16. • CPU • RAM • DISK Scaling (vertical) © 2017 Pythian. Confidential
  • 17. • Method for distributing data across multiple machines • Splitting data across multiple horizontal partitions Scaling (horizontal) - Sharding © 2017 Pythian. Confidential
  • 18. Sharding with MongoDB Shard © 2017 Pythian. Confidential Shard Data
  • 19. Sharding with MongoDB • Shard/Replica set (subset of the sharded data) • Config servers (metadata and config settings) • mongos (query router, cluster interface) © 2017 Pythian. Confidential Shard Data
  • 20. Sharding with MongoDB • Shard/Replica set (subset of the sharded data) • Config servers (metadata and config settings) • mongos (query router, cluster interface) sh.addShard("shardName") © 2017 Pythian. Confidential A B
  • 21. Shards • Contains subset of sharded data • Replica set for redundancy and HA • Primary shard • Non sharded collections • --shardsvr in config file (port 27018) © 2017 Pythian. Confidential
  • 22. Config servers • Config servers as replica set only (>= 3.4) • Stores the metadata for sharded cluster in config database • Authentication configuration information in admin database • Holds balancer on Primary node (>= 3.4) • --configsvr in config file (port 27019) © 2017 Pythian. Confidential
  • 23. mongos • Caching metadata from config servers • Routes queries to shards • No persistent state • Updates cache on metadata changes • Holds balancer (mongodb <= 3.2) • mongos version 3.4 can not connect to earlier mongod version © 2017 Pythian. Confidential
  • 24. Sharding collection • Enable sharding on database sh.enableSharding("users") • Shard collection sh.shardCollection("users.history", { user_id : 1 } ) • Shard key - indexed key that exists in every document ○ range based sh.shardCollection("users.history", { user_id : 1 } ) ○ hashed based sh.shardCollection( "users.history", { user_id : "hashed" } ) © 2017 Pythian. Confidential
  • 25. Shard keys and chunks Choosing Shard key • Large Shard Key Cardinality • Low Shard Key Frequency • Non-Monotonically changing shard keys Chunks • A contiguous range of shard key values within a particular shard • Inclusive lower and exclusive upper range based on shard key • Default size of 64MB © 2017 Pythian. Confidential
  • 26. Ranged sharding • Dividing data into contiguous ranges determined by the shard key values • Documents with “close” shard key values are likely to be in the same chunk or shard • Query Isolation - more likely to target single shard © 2017 Pythian. Confidential
  • 27. Hashed sharding • Uses a hashed index of a single field as the shard key to partition data • More even data distribution at the cost of reducing Query Isolation • Applications do not need to compute hashes • Keys that change monotonically like ObjectId or timestamps are ideal © 2017 Pythian. Confidential
  • 28. Shard keys limitations • Must be ascending indexed key or indexed compound keys that exists in every document in the collection • Cannot be multikey index, a text index or a geospatial index • Cannot exceed 512 bytes • Immutable key - can not be updated/changed • Update operations that affect a single document must include the shard key or the _id field • No option for sharding if unique indexes on other fields exist • No option for second unique index if the shard key is unique index © 2017 Pythian. Confidential
  • 29. Summary • Replica set with odd number of voting members • Hidden or Delayed member for dedicated functions (backups …) • Dataset fits into single server, keep unsharded deployment • Horizontal scaling - shards running as replica sets • Shard keys are immutable with max size of 512 bytes • Shard keys must exists in every document in the collection • Ranged sharding may not distribute the data evenly • Hashed sharding distributes the data randomly © 2017 Pythian. Confidential