Book Image

MongoDB High Availability

By : Afshin Mehrabani
Book Image

MongoDB High Availability

By: Afshin Mehrabani

Overview of this book

Table of Contents (17 chapters)
MongoDB High Availability
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Preface

Before the invention of NoSQL, almost all databases were structural. This means that developers had to define the structure of the database before using it. Despite all the benefits of using this approach, sometimes, following such a method came with issues. For instance, you couldn't (or at least it was difficult to) have schemaless data.

Later, the NoSQL concept and all the technologies related to it were invented to rescue programmers.

The following sections show a brief history of the term NoSQL, which is taken from http://en.wikipedia.org/wiki/NoSQL.

"Carlo Strozzi used the term NoSQL in 1998 to name his lightweight, open source relational database that did not expose the standard SQL interface."

NoSQL databases are classified in the following ways:

  • Column (HBase, Cassandra)

  • Document (MongoDB, Couchbase)

  • Key-value (Redis, Riak, MemcacheDB)

  • Graph (Neo4j, OrientDB)

Have a look at the following image:

So, why use NoSQL instead of relational databases? There are many different opinions about the benefits of relational or non-relational databases, but to give you the gist of all conversations, the following are the major reasons to use NoSQL:

  • A more flexible data model and a dynamic schema

  • Scalability

  • Better efficiency and performance

Compared to relational database systems, NoSQL databases have a remarkable feature that enables developers to change the data model after inserting data; that is, developers can insert data without defining the data model. This comes in handy when you have a data model that might change after data is inserted.

One of the great NoSQL database facilities is scaling. Almost all NoSQL technologies support a built-in mechanism to scale a database horizontally, and not vertically. Auto-sharding is responsible for this task.

Additionally, NoSQL databases support integrated caching, which improves the read/write performances of a database. The database will frequently use data in memory and restore them while reading data, but not from the disk. This method will affect database performance and improve the overall database speed when reading and writing data.

MongoDB is one of the pioneers in implementing the NoSQL concept by using "Document" as the infrastructure when saving and restoring data from a database. MongoDB is a cross-platform, document-oriented database system. MongoDB was developed by 10gen, a software company, in October 2007. The latest stable version of MongoDB is 2.4.9, and was released on January 10, 2014.

MongoDB is the leading NoSQL database, with stunning implementation, and it has a vibrant community. As you know, one of the basic reasons to choose a technology is an active and lively community so there is always someone who can help you and answer your questions. The graph, shown in the following screenshot is taken from http://www.mongodb.com/leading-nosql-database:

You can ask your questions in StackOverflow or on their individual forums, and you will get an answer at the earliest. Furthermore, there are various books and articles available about MongoDB.

Here, we have some remarkable features of MongoDB:

  • Schemaless data: Developers are able to store any data model or change the schema during or after inserting data.

  • Replication: MongoDB provides high availability with replica sets. A replica set contains two or more copies of data, and each one can be either primary or secondary.

  • Load balancing: Using sharding, MongoDB can scale horizontally, so data will split between two ranges based on sharding keys.

  • File storage: MongoDB has a feature that is called GridFS, so you can use MongoDB as a filesystem to store and load data from the disk.

In this book, we will discuss remedies and solutions to provide a highly available MongoDB server. First of all, we will go through the problems and issues that cause server downtime, such as errors or server crashes. In the next chapters, by introducing remedies and exploring the problem with a real-world example, we will sort out the issues.

What this book covers

Chapter 1, Understanding the MongoDB Architecture and Processes, discusses the MongoDB architecture, its processes, and binary files such as, mongos or mongod.

Chapter 2, Understanding MongoDB's Failures and Limitations, covers MongoDB's failures, such as server downtime, errors while inserting or reading, and so on. Also, we discuss the solutions to cover and reduce downtime.

Chapter 3, Clustering in MongoDB, provides an overview of MongoDB clustering solutions in a production environment.

Chapter 4, Utilizing a Replica Set, covers replica sets and explains the basic concepts of this feature.

Chapter 5, Replica Set in Action, introduces real-world examples using replica sets to provide high availability for the server.

Chapter 6, Understanding the Concept of Sharding, explains the understanding and utilization of the sharding feature in MongoDB.

Chapter 7, Sharding in Action, explains the use of sharding in action, to enable clustering in an existing MongoDB database and even in a new one.

Chapter 8, Analyzing and Improving Database Performance, covers using the latest MongoDB features to boost the reading and writing performance.

Chapter 9, Migrating Instances and Reducing Downtime, teaches the database migrations and solutions to reduce server downtime.

Chapter 10, Monitoring and Troubleshooting the Database, discusses tools and techniques to manage database performance and uptime. Also, this includes a discussion on the ways to troubleshoot database problems.

What you need for this book

Since MongoDB is cross-platform, you can use all operating systems, including Linux, Windows, or Mac OS X.

In this book, we need the latest version of MongoDB. Currently, the latest stable version is 2.6.1, and you can download it from the official MongoDB website.

Who this book is for

The MongoDB High Availability book is a complete manual to use MongoDB in the production environment.

If you need to use MongoDB in production or you are interested to learn about clustering solutions in MongoDB, this book is the right choice. With this step-by-step guide, you can enable features for your database easily and follow the instructions to use the available methods. Familiarity with MongoDB is expected for you to understand the content of this book.

Conventions

In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "In the MongoDB structure, the mongo file is responsible for this task."

A block of code is set as follows:

{
    "_id": ObjectId("725c211a412f812548cv3258"),
    "data": 1
}

Any command-line input or output is written as follows:

-f (file size): unlimited 
-t (cpu time): unlimited 
-v (virtual memory): unlimited
-n (open files): 64000 
-m (memory size): unlimited
-u (processes/threads): 32000

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "MMS supports all types of MongoDB instances, including Sharded Cluster, Standalone, Replica Set, and Master/Slave."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to , and mention the book title via the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.

Piracy

Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.

Questions

You can contact us at if you are having a problem with any aspect of the book, and we will do our best to address it.