Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
MongoDB High Availability

You're reading from  MongoDB High Availability

Product type Book
Published in Jul 2014
Publisher
ISBN-13 9781783986729
Pages 164 pages
Edition 1st Edition
Languages
Author (1):
Afshin Mehrabani Afshin Mehrabani
Profile icon Afshin Mehrabani

Table of Contents (17) Chapters

MongoDB High Availability
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Understanding the MongoDB Architecture and Processes Understanding MongoDB's Failures and Limitations Clustering in MongoDB Utilizing a Replica Set Replica Set in Action Understanding the Concept of Sharding Sharding in Action Analyzing and Improving Database Performance Migrating Instances and Reducing Downtime Monitoring and Troubleshooting the Database Index

Chapter 3. Clustering in MongoDB

As a database gets larger, you need to come up with solutions to improve its performance to support more queries over a period of time and throughput. The most common solution in databases is clustering. Using clustering, you can save data across multiple servers and obviously, share and distribute the pressure of data between different servers. In this chapter, you will learn the basic concepts of clustering in MongoDB.

Sharding in MongoDB


MongoDB has a great solution to provide clustering. Sharding is one of the remarkable MongoDB features that enable developers to easily create a cluster in MongoDB using different mongod instances in between the servers.

Sharding consists of various parts such as replica sets and configuration servers. Before discussing more about clustering and sharding, you need to learn the basic terms of clustering in MongoDB. In the next sections, we will discuss different aspects of the sharding architecture.

Understanding replication

To start with, you need to know the basic components of sharding in MongoDB. One of the major features required for clustering in MongoDB is replication. Replication is a procedure to synchronize data through various servers. Actually, by using replication, you can save or copy the same data between different servers, so this redundancy can protect the database from the data loss of a single server.

Furthermore, replication allows you to use other servers...

Vertical and horizontal scaling


The database systems can be scaled with two basic approaches, vertical or horizontal. In the vertical scaling approach, you need to add more capacity to the existing server, for instance, adding more CPU, RAM or storage to the server. It's obvious that adding more CPU or RAM to the existing server is more expensive and difficult to maintain. The following diagram shows you the process of vertical scaling:

In horizontal scaling, the database system can be scaled through different servers instead of only one server, that is, the database is scaled horizontally rather than vertically. This approach is safer, easier, and less expensive than vertical scaling. The process of horizontal scaling is shown in the following diagram:

Utilizing sharding


Sharding is the solution to address scaling issues in MongoDB. Using sharding, developers can horizontally scale the database over multiple servers. The same dataset is divided over multiple servers. Each individual server calls the shard; it is an independent database. All shards together make the single logical database.

The following diagram shows you the sharding process:

Sharding solves the problem of high overload and large datasets. While inserting or reading data, the client or application needs to access only one shard and not all shards. Hence, this change will horizontally scale the throughput and overload. Consequently, the database can support more operations.

On the other hand, by dividing the whole database over different servers, it reduces the amount of data that each server should store. Hence, each shard holds only a specific part of the whole database. As a result, to store 1 TB database using sharding, you can have four different servers, each having...

Implementing clustering in MongoDB


In this section, we will go through the implementation of a cluster in MongoDB using sharding and replica sets.

Note

A sharded cluster consists of three configuration processes, one or more replica sets, and one or more mongos routing processes.

You can view this at http://docs.mongodb.org/manual/reference/glossary/#term-sharded-cluster.

A sharded cluster in MongoDB consists of three components, configuration servers, shards (replica sets or mongod processes), and mongos. The mongos process is the query router for all clients.

Learning about shards

Shards are replica sets that store each individual part of a database. In a development environment, you can use the mongod process instead of the replica set, but for production, it's recommended that you use the replica set because it provides better performance in high throughput. The replica set is made up of different mongod processes.

Understanding the configuration server

Configuration servers are used to store...

Summary


This chapter was more practical than previous chapters, because you learned the basics of creating and developing a cluster network in MongoDB in order to make a MongoDB server.

First of all, you learned about the replication procedure and how it works. Then, you had a brief description of the replica set architecture. Next, we talked about the replica set failover, how it works, and the replica set election process. We also gave you a detailed explanation of replica set members such as the primary, secondary, and arbiter nodes.

Next, you learned about the sharding network in MongoDB that gives developers the ability to make a sharded cluster network and divide the database over different servers. This action helps us make the MongoDB server mush faster and easier to manage. Furthermore, we learned about vertical and horizontal scaling and why horizontal scaling is better and more efficient than vertical scaling. We also learned about sharded cluster network members such as the configuration...

lock icon The rest of the chapter is locked
You have been reading a chapter from
MongoDB High Availability
Published in: Jul 2014 Publisher: 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.
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}