Using ApsaraDB to Build Scalable MongoDB Instances

本文涉及的产品
云数据库 MongoDB,独享型 2核8GB
推荐场景:
构建全方位客户视图
简介: MongoDB is a star in the non-SQL (NoSQL) database world.

Galera_to_be_phased_out_MySQL_Group_Replication_officially_launched

MongoDB is a star in the non-SQL (NoSQL) database world. It is a proven solution with some interesting use cases (which usually need to be prepared to scale due to the amount of data that has to be processed in short periods of time).

In this article, we'll explore using Alibaba's ApsaraDB for MongoDB service, which allows us to set up NoSQL databases in a simple but scalable way.

MongoDB background

MongoDB was initially released in 2009 and quickly gained momentum thanks to its approach to data organization. Instead of using the common relational paradigm, MongoDB organizes the data in documents using notation based on JSON (JavaScript Object Notation), which gave new capabilities to the developer, and advantages in terms of development speed. The way that users query the data inside a NoSQL database differs from Structured Query Language (SQL). And the way that aggregation, replication and high availability is achieved differs slightly from the usual relational mode.

MongoDB is suitable for a variety of use cases, like location-based mobile apps, and the asynchronous data writing function provided by Alibaba's ApsaraDB for MongoDB makes it a great tool for Internet of Things (IoT) applications because it performs like an in-memory database, which fits perfectly in intensive writing cases. MongoDB indexes and map-reduce aggregation are useful for multidimensional data analysis.

For write-intensive applications, a single instance of MongoDB is usually not enough. Therefore, increasing the availability of your service by running a cluster of databases is a good idea. It enables all of the instances of MongoDB to share a single common interface, but shares the load of client services.

A database ready for the cloud

Running a database cluster is a complicated task. Usually there is a specific role (better, a specific team) in the company that handles this. There are innumerable important details, and a huge amount of subtasks that you need to manage to offer a service that is reliable, scalable and blazing fast. Fortunately, companies like Alibaba offer this kind of service, and the jump from zero to a decent cluster configuration is achievable without requiring a specialist.

ApsaraDB for MongoDB lets you configure groups of three MongoDB instances called replicas (primary, secondary, and a secondary hidden instance). You can create as many replicas as you want, but some complementary systems are available to improve the management tasks of clusters:

Backup System: Backups of MongoDB instances can be configured with several options, and by default, the files are retained for seven (7) days.
HA Control System: Detects problems with primary instances of replicas and switches to the secondary instances.
Log Collection: Collects slow queries and instances' RAM conditions to allow you to tune the performance of your apps.
Monitoring System: Collects metrics (instant measurements of the conditions of your replicas) that are useful to understand the specific running conditions of your cluster in a period of time.
Online Migration System: Migrates data from the available backups to new instances when a physical failure occurs. This way, you achieve high availability levels.
Task Control: Allows you to change the configuration parameters of your instances, backups, etc.
ConfigServer: A cluster configuration server (an optional 1-core 2 GB CPU and 20 GB storage space machine) that allows cluster managers to add Mongo or shard nodes to your cluster.

When you configure a replica, you select the type of instance, which includes the number of cores, RAM size, maximum number of simultaneous connections, and the maximum number of input/output operations per second. Alibaba's ApsaraDB for MongoDB offers over 20 metrics to monitor performance and keeps the data for a year.

Hands-on

To start using ApsaraDB for MongoDB, you have to create an account on Alibaba Cloud. You can take advantage of the USD $300 credit that they currently offer for new users. The registration process is really simple, so we are not going to explain it here in detail. We are going to create a single replica with the primary, secondary and secondary hidden nodes. (ApsaraDB for MongoDB also includes a guide to properly set up a cluster.)

Now, go to the console and click on "ApsaraDB for MongoDB":

01

Click on the "Create Instance" button:

02

Select the region, zone, database number of cores, RAM size, and storage options. (Please assign a strong initial password.) Then click on the "Buy Now" button:

03

Confirm the instance, and after a few seconds, you will have it in the console:

04

When you click on the "Manage" link of the instance, you will be at the management console for the replica:

05

We can configure access to the instance through any Elastic Compute Service (ECS) server because this is just a sample. (This setup is highly risky, and you should avoid it in your other projects' setups. Please read the security guides and collaborate with your IT security team before configuring an instance.)

Now, click on the link "Security Controls" which is on the left panel, and then click the "Manual Modify" button on the bottom and add a comma "," after "127.0.0.1" and "0.0.0.0/0" (which means any IP address). Don't leave any spaces between values:

06

Click the "OK" button, and then your replica will be available to be accessed from any ECS instance. (Again, this is highly risky and should be avoided in all possible ways.) You can check the connection using the MongoDB client with the parameters that are shown at the bottom of the management console.

07

Alternatives

MongoDB is spread in various clouds. As an alternative to the RDBMS, Alibaba's ApsaraDB also supports another kind of NoSQL database, Redis, which is appropriate for another kind of use case, but usually also requires high availability and elastic scalability. If you are interested in further exploring the NoSQL world, there are also graph databases (Neo4j, ArangoDB), columnar-oriented (Apache Kudu, Apache Parquet, InfiniDB), and even mixed.

Final words

After reading some documentation, and a couple of hours of work, it is pretty simple to set up a basic MongoDB replica using Alibaba's ApsaraDB for MongoDB. The console and management services are simple and intuitive. The ability to set up a real cluster solution with a few clicks, keeping compatibility with one of the most-used NoSQL engines is appealing, but there are some points that should be polished, like the localization of management tools and the written documentation.

Bio
Nicolas Bohorquez (@Nickmancol) is a software developer from Colombia and is currently earning a Master's in Data Science for Complex Economic Systems at the Collegio Carlo Alberto in Turin, Italy. Previously, Nicolas has been part of development teams in a handful of startups, and has founded three companies in the Americas. He is passionate about the modeling of complexity and the use of data science to improve the world.

相关实践学习
MongoDB数据库入门
MongoDB数据库入门实验。
快速掌握 MongoDB 数据库
本课程主要讲解MongoDB数据库的基本知识,包括MongoDB数据库的安装、配置、服务的启动、数据的CRUD操作函数使用、MongoDB索引的使用(唯一索引、地理索引、过期索引、全文索引等)、MapReduce操作实现、用户管理、Java对MongoDB的操作支持(基于2.x驱动与3.x驱动的完全讲解)。 通过学习此课程,读者将具备MongoDB数据库的开发能力,并且能够使用MongoDB进行项目开发。   相关的阿里云产品:云数据库 MongoDB版 云数据库MongoDB版支持ReplicaSet和Sharding两种部署架构,具备安全审计,时间点备份等多项企业能力。在互联网、物联网、游戏、金融等领域被广泛采用。 云数据库MongoDB版(ApsaraDB for MongoDB)完全兼容MongoDB协议,基于飞天分布式系统和高可靠存储引擎,提供多节点高可用架构、弹性扩容、容灾、备份回滚、性能优化等解决方案。 产品详情: https://www.aliyun.com/product/mongodb
目录
相关文章
|
存储 API 索引
【Elastic Engineering】Elasticsearch:Cluster 备份 Snapshot 及 Restore API
Elasticsearch:Cluster 备份 Snapshot 及 Restore API
248 0
【Elastic Engineering】Elasticsearch:Cluster 备份 Snapshot 及 Restore API
|
JSON JavaScript NoSQL
Invoice Application Backend Using ApsaraDB for MongoDB
In part three of this three-part tutorial, we will explore how to create the backend of a fully functional invoice application using ApsaraDB for MongoDB.
2780 0
Invoice Application Backend Using ApsaraDB for MongoDB
|
SQL 关系型数据库 MySQL
Best Practices for RDS MySQL Storage Optimization
This article talks about spatial optimization of ApsaraDB for RDS MySQL. We will discuss the various objects which comprise the RDS Console with an understanding of the composition of objects.
1667 0
Best Practices for RDS MySQL Storage Optimization
|
弹性计算 NoSQL 安全
AMP for E-Commerce Part 2: Creating Backend with Alibaba Cloud ApsaraDB for MongoDB
In this three-part tutorial, we will explore how to create a fully functional e-commerce mobile application using AMP.
1571 0
AMP for E-Commerce Part 2: Creating Backend with Alibaba Cloud ApsaraDB for MongoDB
|
NoSQL
An Insight into MongoDB Sharding Chunk Splitting and Migration
Sharding is a method of data distribution across multiple machines. MongoDB uses sharding to support deployments with very large data sets and high throughput operations.
3075 0
|
NoSQL
How to Create Highly Available MongoDB Databases with Replica Sets
Find out how you can create MongoDB databases with high availability by backing up data through replica set elections.
4115 0
How to Create Highly Available MongoDB Databases with Replica Sets
|
SQL 弹性计算 关系型数据库
Performance Testing: Self-built Databases vs. ApsaraDB for RDS
Poorly configured ApsaraDB instances may appear to underperform compared with self-built databases.
2828 0
|
NoSQL
High-availability MongoDB Cluster Configuration Solutions
In this post, we will share an in-depth discussion about High-availability Cluster Solutions along with several MongoDB High-availability Cluster Configurations.
2922 0
High-availability MongoDB Cluster Configuration Solutions
|
关系型数据库 PostgreSQL RDS
Partitioned Index - Alibaba Cloud RDS PostgreSQL Best Practices
When should you partition a table in your database? Learn how to split tables with partial index.
2077 0
|
SQL 关系型数据库 C语言
Full-text Search Index Optimization - Alibaba Cloud RDS PostgreSQL Best Practices
Will indexes be used in full-text searches that do not contain a certain keyword? Learn more about GIN, Generalized Inverted Index.
3953 0