Sharding in MongoDb - In just 5 minutes

You are here : Home / MongoDB Tutorial


Contents of page >


1) What is Sharding in mongoDB?
Sharding is the process of distributing the data across across multiple servers/machines.
2) What are advantages of Sharding in MongoDB?
  • To provide faster access to data (It's faster to fetch and store data across multiple servers ). As all data stored on same database server can reduce read and write speed.
  • Huge data storage capacity (Multiple machines together will have huge storage capacity) - As single database may not have too much storage capacity to hold such huge data.
  • High availability.


3) Handling the data growth - There are two ways to address the growth of data on system >
  • 3.1) Vertical Scaling - In this scaling we might use -
    • More powerful CPU,
    • Increased capacity RAM, or
    • Increased storage space.
Cons of Vertical Scaling -
  • It is very costly to deploy such high end system.


  • 3.2) Horizontal Scaling - In this scaling we might  -
    • Divide the system data and load across multiple servers (In this case each machine handles a subset of the overall workload)
Cons of Horizontal Scaling -
  • Complex infrastructure,
  • Complex configuration and
  • It becomes difficult to maintain.
  • Horizontal Scaling is done by SHARDING.

4) Diagram to represent Sharding in MongoDB >
Diagram of Sharding in MongoDB - using sharded cluster >


Let’s discuss the data sharding diagram of MongoDB>
  • Routers (mongos)
    • mongos receive client request.
    • Routes request to specific shard.
  • Config ServersConfig servers store cluster’s metadata and configuration settings for the cluster.
This metadata information is used by router to route request to specific shard.
  • Shards − Shards are replica set.
    • Shards store the data.
5) At what level data is sharded in MongoDB?
MongoDB shards data at the collection (same as table in RDBMS) level,
distributing the collection data across the shards in the cluster.


6) Chunks in MongoDB -
MongoDB partitions sharded data into chunks.
Let’s look data sharding in steps >
  1. MongoDB partitions sharded data into chunks.
  2. Then MongoDB
    1. migrates chunks -
    2. across the shards -
7) Summary -


So in this mongoDB tutorial we learned what is Sharding in MongoDb.
Sharding is the process of distributing the data across across multiple servers/machines.
What are advantages of Sharding in MongoDB?
  • Shrading provides faster access to data
  • Huge data storage capacity


Handling the data growth - using
  • 3.1) Vertical Scaling - Using powerful CPU, Increased capacity RAM, Increased storage space.etc.


  • 3.2) Horizontal Scaling - Divide the system data and load across multiple servers


  • Horizontal Scaling is done by SHARDING.


Sharding process includes >
  • Routers (mongos)
  • Config Servers
  • Shards


Having any doubt? or you liked the tutorial! Please comment in below section.
Please express your love by liking JavaMadeSoEasy.com (JMSE) on facebook, following on google+ or Twitter. You may join our fbGroup or linkedInGroup as well.



RELATED LINKS>

Labels: MongoDB
eEdit
Must read for you :