SlideShare a Scribd company logo
@agatestudio
Replication and Sharding on
MongoDB
Tonny K
Publishing
Agate Studio
@agatestudio
CONTENT
Introduction
Replication
• Replication: Concepts
• Replication: How to
Sharding
• Sharding: Concepts
• Sharding: How to
@agatestudio
Introduction
• Replication increases data availability
With multiple copies of data on different database servers,
replication protects a database from the loss of a single
server
• Sharding addresses the challenge of scaling to
support large data sets
As the size of the data increases, a single machine may not
be sufficient to store the data. With Sharding we can
distribute data across multiple servers
@agatestudio
Replication: Concepts
• Replication is the process of synchronizing data
across multiple servers
• You can use replication to increase read capacity
• Provide high availability using automatic failover
Replication: Concepts• Replica set Members
– Primary: accepts all write
operations from clients
– Secondary: maintains a copy
of the primary’s data set.
Replication: Concepts• Automatic Failover
The loss of a primary triggers
an election where one of the
secondaries becomes the new
primary
@agatestudio
Replication: How to
1. Install MongoDB
– # yum install mongo-10gen mongo-10gen-server
2. Configure
– port = 27017
– bind_ip = 192.168.56.107
– dbpath = /srv/mongodb/
– fork = true
– replSet = rs1
3. Start Instances
– # mongod --config /etc/mongodb.conf
4. Connect To Instance
– $ mongo <host>
5. Initiate and Add Replica set member
– rs.initiate()
– rs.add("<hostname>:<port>")
– rs.conf()
@agatestudio
Sharding: Concepts
• Sharding is the process of storing data records across
multiple machines
• Sharding reduces the amount of data that each server
needs to store
• MongoDB distributes data, or shards, at the collection
level
• Sharding partitions a collection’s data by the shard key.
@agatestudio
Sharding: Concepts
• Shard Key
– A shard key is either an indexed field or an indexed
compound field that exists in every document in the
collection
– MongoDB divides the shard key values into chunks and
distributes the chunks evenly across the shards
Sharding: Concepts
• Data Partitioning
– Range Based Sharding
– Hash Based Sharding
Sharding: Concepts
• Components
– Router
routes the reads and writes
from applications to the shards
– Config Server
holds metadata about the
cluster
– Shard
holds a subset of a collection’s
data
Sharding: Concepts
• Maintaining a Balanced Data Distribution
ChunkMigration
Chunk Splitting
@agatestudio
Sharding: How to
1. Create Data directory for each Config Server & start instances
– mkdir /data/configdb
– mongod --configsvr --dbpath <path> --port <port>
2. Start Router (mongos instance)
– mongos --configdb <config server hostnames>
3. Connect To Mongos Instance
– mongo --host <hostname> --port <port>
4. Add each shard to the cluster
– sh.addShard( "mongodb0.example.net:27017" )
5. Enable Sharding for A Database
– sh.enableSharding("<database>")
6. Enable Sharding for Collections
– sh.shardCollection("<database>.<collection>", shard-key-pattern)
THANK YOU

More Related Content

ODP
MongoDB: Advance concepts - Replication and Sharding
DOCX
MongoDB Replication and Sharding
PDF
Cassandra - A Decentralized Structured Storage System
PPTX
Availability and scalability in mongo
PPTX
Boot Strapping in Cassandra
PPTX
Cassandra - Research Paper Overview
PPTX
Cassandra - A decentralized storage system
PPTX
GFS & HDFS Introduction
MongoDB: Advance concepts - Replication and Sharding
MongoDB Replication and Sharding
Cassandra - A Decentralized Structured Storage System
Availability and scalability in mongo
Boot Strapping in Cassandra
Cassandra - Research Paper Overview
Cassandra - A decentralized storage system
GFS & HDFS Introduction

What's hot (20)

PPTX
Accessing external hadoop data sources using pivotal e xtension framework (px...
PPTX
Hadoop architecture by ajay
PDF
Big data interview questions and answers
PDF
Hadoop hdfs interview questions
PPT
July 2010 Triangle Hadoop Users Group - Chad Vawter Slides
ODP
MySQL HA
PDF
The Google Bigtable
PPTX
Hadoop distributed file system
PDF
Introduction to Hadoop
PPTX
Cassandra - Deep Dive ...
PDF
Introduction to apache hadoop
PDF
Hadoop HDFS
PPTX
Hadoop migration and upgradation
PPT
8. key value databases laboratory
ODP
Architecture of Hadoop
PDF
Apache Cassandra Multi-Datacenter Essentials (Julien Anguenot, iLand Internet...
PDF
Hadoop interview questions
PPTX
HDFS: Hadoop Distributed Filesystem
DOCX
Upgrading hadoop
Accessing external hadoop data sources using pivotal e xtension framework (px...
Hadoop architecture by ajay
Big data interview questions and answers
Hadoop hdfs interview questions
July 2010 Triangle Hadoop Users Group - Chad Vawter Slides
MySQL HA
The Google Bigtable
Hadoop distributed file system
Introduction to Hadoop
Cassandra - Deep Dive ...
Introduction to apache hadoop
Hadoop HDFS
Hadoop migration and upgradation
8. key value databases laboratory
Architecture of Hadoop
Apache Cassandra Multi-Datacenter Essentials (Julien Anguenot, iLand Internet...
Hadoop interview questions
HDFS: Hadoop Distributed Filesystem
Upgrading hadoop
Ad

Similar to MongoDB by Tonny (20)

PPTX
MongoDB : Scaling, Security & Performance
PDF
Data has a better idea the in-memory data grid
PPTX
Cloud computing UNIT 2.1 presentation in
PPTX
Capacity Planning
PPTX
Hardware Provisioning
PDF
Spark Summit EU talk by Ross Lawley
PDF
How To Connect Spark To Your Own Datasource
PPTX
MongoDB Internals
PDF
Scaling MongoDB - Presentation at MTP
ODP
Big data nyu
PPT
AWS (Hadoop) Meetup 30.04.09
KEY
The Care + Feeding of a Mongodb Cluster
PPTX
Azure Data Factory Data Flow Performance Tuning 101
PDF
Scalability Considerations
PPT
HDFS_architecture.ppt
PDF
Cloud Infrastructures Slide Set 8 - More Cloud Technologies - Mesos, Spark | ...
PPTX
Back to Basics: Build Something Big With MongoDB
PPTX
cybersecurity notes for mca students for learning
PPTX
Webinar: Serie Operazioni per la vostra applicazione - Sessione 6 - Installar...
PPTX
Back tobasicswebinar part6-rev.
MongoDB : Scaling, Security & Performance
Data has a better idea the in-memory data grid
Cloud computing UNIT 2.1 presentation in
Capacity Planning
Hardware Provisioning
Spark Summit EU talk by Ross Lawley
How To Connect Spark To Your Own Datasource
MongoDB Internals
Scaling MongoDB - Presentation at MTP
Big data nyu
AWS (Hadoop) Meetup 30.04.09
The Care + Feeding of a Mongodb Cluster
Azure Data Factory Data Flow Performance Tuning 101
Scalability Considerations
HDFS_architecture.ppt
Cloud Infrastructures Slide Set 8 - More Cloud Technologies - Mesos, Spark | ...
Back to Basics: Build Something Big With MongoDB
cybersecurity notes for mca students for learning
Webinar: Serie Operazioni per la vostra applicazione - Sessione 6 - Installar...
Back tobasicswebinar part6-rev.
Ad

More from Agate Studio (20)

PDF
Digital Coloring by Raksa
PDF
Computational Advertising by Icha
PDF
Freemium conceptanalytics leemarvin
PDF
Game Programming Pattern by Restya
PDF
Community Management by Yudhit
PDF
[Habli] tds agustus
PDF
Wp quality bar tedy
PDF
Toku DB by Aswin
PDF
Lee marvin pitching-hacks
PDF
Emotiv EPOC by Neneng
PDF
Aksi – Koneksi – Deviasi by Valent
PDF
MMO Design Architecture by Andrew
PDF
How to Persuade People by Dave
PDF
Eddie supersmash goodminton
PDF
Satriyo digital audio gears
PDF
Yinan heroes of-the_strom
PDF
Advanced encryption standard (aes) epul
PDF
Real Time Framework by Tonny
PDF
Unity Camera & Simple Image Editing by Puthut
PDF
Hibernate by Jason
Digital Coloring by Raksa
Computational Advertising by Icha
Freemium conceptanalytics leemarvin
Game Programming Pattern by Restya
Community Management by Yudhit
[Habli] tds agustus
Wp quality bar tedy
Toku DB by Aswin
Lee marvin pitching-hacks
Emotiv EPOC by Neneng
Aksi – Koneksi – Deviasi by Valent
MMO Design Architecture by Andrew
How to Persuade People by Dave
Eddie supersmash goodminton
Satriyo digital audio gears
Yinan heroes of-the_strom
Advanced encryption standard (aes) epul
Real Time Framework by Tonny
Unity Camera & Simple Image Editing by Puthut
Hibernate by Jason

Recently uploaded (20)

PDF
Paper A Mock Exam 9_ Attempt review.pdf.
PPTX
Lesson notes of climatology university.
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PPTX
UNIT III MENTAL HEALTH NURSING ASSESSMENT
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
01-Introduction-to-Information-Management.pdf
PDF
What if we spent less time fighting change, and more time building what’s rig...
PDF
LNK 2025 (2).pdf MWEHEHEHEHEHEHEHEHEHEHE
PPTX
Cell Structure & Organelles in detailed.
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PDF
Updated Idioms and Phrasal Verbs in English subject
PPTX
master seminar digital applications in india
PPTX
UV-Visible spectroscopy..pptx UV-Visible Spectroscopy – Electronic Transition...
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
RMMM.pdf make it easy to upload and study
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
Paper A Mock Exam 9_ Attempt review.pdf.
Lesson notes of climatology university.
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Microbial diseases, their pathogenesis and prophylaxis
UNIT III MENTAL HEALTH NURSING ASSESSMENT
Supply Chain Operations Speaking Notes -ICLT Program
01-Introduction-to-Information-Management.pdf
What if we spent less time fighting change, and more time building what’s rig...
LNK 2025 (2).pdf MWEHEHEHEHEHEHEHEHEHEHE
Cell Structure & Organelles in detailed.
202450812 BayCHI UCSC-SV 20250812 v17.pptx
Updated Idioms and Phrasal Verbs in English subject
master seminar digital applications in india
UV-Visible spectroscopy..pptx UV-Visible Spectroscopy – Electronic Transition...
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
RMMM.pdf make it easy to upload and study
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf

MongoDB by Tonny

  • 1. @agatestudio Replication and Sharding on MongoDB Tonny K Publishing Agate Studio
  • 2. @agatestudio CONTENT Introduction Replication • Replication: Concepts • Replication: How to Sharding • Sharding: Concepts • Sharding: How to
  • 3. @agatestudio Introduction • Replication increases data availability With multiple copies of data on different database servers, replication protects a database from the loss of a single server • Sharding addresses the challenge of scaling to support large data sets As the size of the data increases, a single machine may not be sufficient to store the data. With Sharding we can distribute data across multiple servers
  • 4. @agatestudio Replication: Concepts • Replication is the process of synchronizing data across multiple servers • You can use replication to increase read capacity • Provide high availability using automatic failover
  • 5. Replication: Concepts• Replica set Members – Primary: accepts all write operations from clients – Secondary: maintains a copy of the primary’s data set.
  • 6. Replication: Concepts• Automatic Failover The loss of a primary triggers an election where one of the secondaries becomes the new primary
  • 7. @agatestudio Replication: How to 1. Install MongoDB – # yum install mongo-10gen mongo-10gen-server 2. Configure – port = 27017 – bind_ip = 192.168.56.107 – dbpath = /srv/mongodb/ – fork = true – replSet = rs1 3. Start Instances – # mongod --config /etc/mongodb.conf 4. Connect To Instance – $ mongo <host> 5. Initiate and Add Replica set member – rs.initiate() – rs.add("<hostname>:<port>") – rs.conf()
  • 8. @agatestudio Sharding: Concepts • Sharding is the process of storing data records across multiple machines • Sharding reduces the amount of data that each server needs to store • MongoDB distributes data, or shards, at the collection level • Sharding partitions a collection’s data by the shard key.
  • 9. @agatestudio Sharding: Concepts • Shard Key – A shard key is either an indexed field or an indexed compound field that exists in every document in the collection – MongoDB divides the shard key values into chunks and distributes the chunks evenly across the shards
  • 10. Sharding: Concepts • Data Partitioning – Range Based Sharding – Hash Based Sharding
  • 11. Sharding: Concepts • Components – Router routes the reads and writes from applications to the shards – Config Server holds metadata about the cluster – Shard holds a subset of a collection’s data
  • 12. Sharding: Concepts • Maintaining a Balanced Data Distribution ChunkMigration Chunk Splitting
  • 13. @agatestudio Sharding: How to 1. Create Data directory for each Config Server & start instances – mkdir /data/configdb – mongod --configsvr --dbpath <path> --port <port> 2. Start Router (mongos instance) – mongos --configdb <config server hostnames> 3. Connect To Mongos Instance – mongo --host <hostname> --port <port> 4. Add each shard to the cluster – sh.addShard( "mongodb0.example.net:27017" ) 5. Enable Sharding for A Database – sh.enableSharding("<database>") 6. Enable Sharding for Collections – sh.shardCollection("<database>.<collection>", shard-key-pattern)