Reader small image

You're reading from  MongoDB High Availability

Product typeBook
Published inJul 2014
Publisher
ISBN-139781783986729
Edition1st Edition
Tools
Right arrow
Author (1)
Afshin Mehrabani
Afshin Mehrabani
author image
Afshin Mehrabani

Afshin Mehrabani is an open source programmer. He is studying to be a computer software engineer. He started programming and web development when he was 12 years old, as well as starting with PHP. Later, he joined the Iran Technical and Vocational Training Organization. He secured the first place and received a gold medal in a competition which was conducted across the entire country in the area of web development. He became a member of the Iran National Foundation of Elite after producing a variety of new programming ideas. He was a software engineer at the Tehran Stock Exchange and is now the head of the web development team in the Yara Company. He cofounded the Usablica team in early 2012 to develop and produce usable applications. He is the author of IntroJs, WideArea, flood.js and some other open source projects. He has contributed to Socket.IO, Engine.IO, and some other open source projects. He is also interested in creating and contributing to open source applications, writing programming articles, and challenging himself with new programming technologies. He has written different articles about JavaScript, Node.js, HTML5, and MongoDB that have been published on different academic websites. Afshin has 5 years of experience in PHP, Python, C#, JavaScript, HTML5, and Node.js in many financial and stock trading projects.
Read more about Afshin Mehrabani

Right arrow

Chapter 6. Understanding the Concept of Sharding

After learning about replication and replica sets, we can jump into the more complex concepts of MongoDB. In this chapter, we will talk about one of the most valuable MongoDB features, that is, sharding. Using this feature, you can spread your data across different servers to distribute operation pressure between different machines and provide better performance.

In this chapter, we will learn the basic terms and concepts of sharding. In the next chapter, we will configure and set up a server from scratch.

Understanding scaling


When you are using MongoDB in a production environment and under high throughput, you may face a lack of server resources. Storing large datasets on a single machine can be the biggest problem. In addition, responding to a lot of read/write requests from different clients can be a concern because these kinds of processes are resource-consuming and can exhaust the server's resources.

To address these problems, scale your database system to support more clients. Basically, there are two ways to scale a system, vertical scaling and horizontal scaling.

In the vertical scaling approach, the system administrator will add more resources and capacities to an existing server. However, adding more capacity to an existing system has some limitations, making this approach less useful. Adding more CPU cores or RAM capacity to a machine can be more expensive than setting up a new smaller machine. Meanwhile, some cloud-based service providers don't offer very large capacity machines...

Learning about sharding


The good news is that MongoDB has come up with a clever solution to scale your database system easily. Sharding is a technique used to scale a database horizontally.

Using sharding, the entire database is divided into separate single databases on different machines. Finally, using a query router, all the separate nodes make a single logical database.

Let's look at an example of sharding. Suppose we have a database sized 1 TB. Storing such a large dataset on a single server is a big challenge, so we use sharding to divide the entire database into smaller instances called shards.

In order to reduce the size of the entire database, we divide it into databases sized 256 GB. During the sharding procedure, each part of the database is divided using a shard key and other options that configure settings for shards such as the size of the dataset.

The following diagram illustrates the example of a 1 TB database being sharded across four instances:

The benefits of using sharding...

Summary


In this chapter, you learned the basic terms, concepts, and components of creating a sharded cluster and using the sharding technique in MongoDB. First, we discussed the different methods of scaling a database system, vertical and horizontal scaling. Then, we introduced the sharding method, which is the horizontal scaling solution for MongoDB.

Also, you learned about the different parts and components of sharding, shards, query routers, and configuration servers. Next, you learned one of the important parts of the sharding procedure, the shard key. Then, all the techniques available to define a shard key were introduced and in the next section, we talked about performance difference between methods. Furthermore, we discussed splitting and balancing processes, which help with maintenance and retention of the balance of data size and chunks in the shards.

In the next chapter, we will configure and establish a sharded cluster from scratch using terms and concepts that we have learned...

lock icon
The rest of the chapter is locked
You have been reading a chapter from
MongoDB High Availability
Published in: Jul 2014Publisher: ISBN-13: 9781783986729
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Afshin Mehrabani

Afshin Mehrabani is an open source programmer. He is studying to be a computer software engineer. He started programming and web development when he was 12 years old, as well as starting with PHP. Later, he joined the Iran Technical and Vocational Training Organization. He secured the first place and received a gold medal in a competition which was conducted across the entire country in the area of web development. He became a member of the Iran National Foundation of Elite after producing a variety of new programming ideas. He was a software engineer at the Tehran Stock Exchange and is now the head of the web development team in the Yara Company. He cofounded the Usablica team in early 2012 to develop and produce usable applications. He is the author of IntroJs, WideArea, flood.js and some other open source projects. He has contributed to Socket.IO, Engine.IO, and some other open source projects. He is also interested in creating and contributing to open source applications, writing programming articles, and challenging himself with new programming technologies. He has written different articles about JavaScript, Node.js, HTML5, and MongoDB that have been published on different academic websites. Afshin has 5 years of experience in PHP, Python, C#, JavaScript, HTML5, and Node.js in many financial and stock trading projects.
Read more about Afshin Mehrabani