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 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.
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.
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":
Click on the "Create Instance" button:
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:
Confirm the instance, and after a few seconds, you will have it in the console:
When you click on the "Manage" link of the instance, you will be at the management console for the replica:
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:
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.
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.
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.
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.
Alibaba Cloud Product Launch - December 17, 2018
Alibaba Clouder - November 20, 2018
Alibaba Clouder - April 3, 2018
- November 14, 2017
Alibaba Clouder - December 17, 2018
ApsaraDB - September 3, 2018
More Posts by Alibaba Clouder