AMP for E-Commerce Part 2: Creating Backend with Alibaba Cloud ApsaraDB for MongoDB

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
云数据库 MongoDB,独享型 2核8GB
推荐场景:
构建全方位客户视图
简介: In this three-part tutorial, we will explore how to create a fully functional e-commerce mobile application using AMP.

By Sai Sarath Chandra, Alibaba Cloud Tech Share Author and Alibaba Cloud MVP

This blog entry is a continuation of the articleAMP for E-Commerce Part 1. Before we start exploring Alibaba Cloud ApsaraDB for MongoDB, we will discuss why we chose this as the backend for the proof of concept (POC).

Relational vs. Non-Relational Databases

In general, there are two types of databases:

  • Relational databases
  • Non-relational databases

In relational databases, we need to know exactly what data we are going to manage. We need to model the database and then create the query corresponding to the data model and fetch accordingly. A typical example of a very popular relational databases is MySQL. MySQL has become an inexpensive option for so many organizations. Although relational databases are powerful, they do have certain limitations. Relational databases are unsuitable for processing high data volumes and is not good at addressing the needs of the changing data.

In the digital Era we see a fluid data where we don't know the exact representation of the data. The data model keeps changing for a particular entity, and that's how the NoSQL data model came into existence. One of such popular NoSQL databases MongoDB. NoSQL is quite a hot topic in the industry now. It is mainly suited for the small and medium level organizations where they want to start up their business but are not clear about what the data might be. NoSQL doesn't have any predefined schema. As a developer, you do not need to worry about having the expertise of a DBA to maintain a well performing backend if you opted for NoSQL.

Benefits of MongoDB

Now we will talk more about the MongoDB and the benefits of using the MongoDB over relational databases like MySQL.

Mongo DB Is Schemaless

In relational databases, we define the table schema before any other data operation. Whenever we insert some data into the table we need to make sure we adhere to the schema of the table. If you think there is a change in the model of the data then we need to change the entire table schema or we need to create a new table and normalize it. But in MongoDB the data is stored in JSON like structures.

In relational databases we have table which consists of rows of data; in MongoDB we have collection which consists the data as documents. A typical document would be nothing more than a JSON like structure. The interesting part in MongoDB is that multiple documents can consist multiple field with multiple data types. Initially, it may seem a little confusing to use MongoDB, but after getting used to it, you will enjoy the flexibility it offers.

MongoDB Is Reliable

We can all agree that relational databases available in the market are backed by years of research and proven industry adoption. However, we should also notice that the MongoDB is also adopted by big companies like T-mobile, Sony, Surveymonkey, Foursquare, Invision, and many others.

MongoDB Is Easy to Scale (Sharding and Replication)

Sharding refers to dividing your dataset up over multiple MongoDB servers. You pick a field to act as a division point in your dataset, referred to as a shard keys. Based on this shard key, data is distributed across multiple servers. Sharding allows for horizontal scaling, which is difficult to implement in MySQL.

There are two scenarios that might ultimately motivate you to shard MongoDB: your dataset has become truly massive and indexes cannot fit in memory any longer, or your application is write-heavy and you need to distribute writes over multiple servers

MongoDB supports built-in replication sharding and auto-elections. Using auto-elections, you can set up a secondary database to automatically take over if the primary database fails. MongoDB uses replica sets to create multiple copies of the data. Each member of the replica set can have the role of primary or secondary at any point in the process. Reads and writes are done on the primary replica by default and then replicated to the secondary replicas.

Replication and sharding makes mongo DB very easy to scale.

Deep Query-Ability, Security, and Developer Friendly

MongoDB supports dynamic queries on documents using a document-based query language that's nearly as powerful as SQL. From the security perspective, MongoDB is more secure because traditional databases can suffer with the SQL injection attacks. For MongoDB, the likelihood of having injection attacks is much lower because of the variable data it stores in the name of its documents.

From the developer perspective, MongoDB is more developer friendly. It is well documented and well-written clients for most major languages. The main advantage with the mongo DB is that the JavaScript based query language that more suited to web developers. It makes prototyping applications much faster, shortening the time for releases and builds

Alibaba Cloud ApsaraDB for MongoDB

Alibaba Cloud ApsaraDB for MongoDB is a secure, reliable, and elastically scalable cloud database service. It currently supports the ReplicaSet and Sharding architectures and can be quickly deployed in just a few steps. The benefits of using Alibaba Cloud ApsaraDB for MongoDB include:

Reliable Storage

  • Built based on Alibaba Cloud Apsara distributed file system and SSD high-performance storage.
  • Three-node ReplicaSet architecture, ensuring redundant data storage.
  • Periodic automatic backup, ensuring reliable data storage.

Elastic Scaling

  • Supports both the ReplicaSet and Sharding architectures.
  • Nodes of the ReplicaSet and Sharding can be upgraded or downgraded as required to scale resources.
  • The number of mongoses and shards in Sharding instances can be scaled out at any time.

Professional Services

  • Senior Alibaba Cloud technical team members available to provide professional services to boost security and resource elasticity.
  • Optimized kernel for performance, security, and other dimensions managed by the source code team.

Cost-effective

  • Cost-effective with no upfront cost or long-term commitment.
  • Offers flexible payment options including Monthly Subscription and Pay-As-You-Go.

Details of ApsaraDB for MongoDB

Architecture

Alibaba Cloud ApsaraDB for MongoDB supports both ReplicaSet Architecture & Sharding Architecture. There will be minimum of three nodes operating in the replica set architecture by default, where one will be primary, another will be secondary and other will be the hidden. If the primary files the system will choose the secondary, for some reason if the secondary is not available then the system switches to the hidden database to make sure the service is available.

The fractional service (shard) and configuration service (configserver) adopt the stable and reliable three-node ReplicaSet architecture.

Security

Alibaba Cloud is well known for its security measures across all its products. ApsaraDB for MongoDB provides built-in backup mechanism and recovery which helps in preventing Data loss and minimising the cost of in proper operation it is also equipped with and Anti-DDoS and supports IP whitelist configuration which supports a maximum of 1000 whitelist rules and performs risk control from the access source.

Management

ApsaraDB for MongoDB also comes with visualized operations and management platform. You can monitor the instance information, such as youth CPU utilization connections, and obtain other information visually. The visualized IT management platform simplifies high-frequency and high-risk operations, such as instance restart. ApsaraDB for MongoDB makes data recovery into a single click operation. It also proactively performs subgrade for database kernel version management, and quickly repairs the defects, freeing you from daily version management.

E-Commerce Store Backend

Now we will create the actual setup for our e-commerce store backend and little bit of networking. We create an architecture something like this going further. Please find the diagram for reference

1

This is the recommended architecture from Alibaba Cloud for accessing the MongoDB instances.

First, we need to create an Alibaba Cloud ECS instance to reduce the complexity of going through the multiple Linux commands. We will create the Windows VM and access MongoDB from the ECS instance.

If you are connecting from the Internet then you need to use the following credentials

IP Address/Host Name: 47.74.237.40 or
Username : Administrator
Password :

2

If you have connected using the Remote Desktop protocol then you should be able to see the Windows connected.

Creating an ApsaraDB for MongoDB Service

Now we will create backend database of the ApsaraDB for MongoDB Service in Alibaba Cloud. On the console, navigate to Products > ApsaraDB for MongoDB.

You will be taken to this screen where I am creating the instance in the same location of the ECS Instance (Singapore). Click on create Instance. For this demo we are creating a "Replica Set Instance"

3

Once you click on the Create Instance Button You will be taken to the below screen. Don't panic if you didn't see the below screen. You will be by default taken to the Subscription (Replica Set). You need to change to the Pay-As-You-Go (Replica Set) model where you can see all the default values are populated. You need to select the VPC model of connection

4

You can see the VPCID and the VSwitchID are populated automatically along with the default configuration. If your configuration is missing the VPCID/VSwitch ID then your ECS Instance or the MongoDB instance is not at the same region. Provide a password and remember it future use for logging into database

5

Once you have done all the steps correctly you should have an active MongoDB service on Alibaba Cloud. You will see the following instance running under the "Singapore" region.

6

Once you click on the instance ID then you will be navigated to this screen where you will see the Intranet & Public IP connection protocols. Before accessing, we need to whitelist the IP address of the ECS instance by clicking at the "Set the whitelist and the address will be displayed".

7

Once you click, you will be navigated here. You have to click on the "Import ECS intranet IP" this will automatically detect the Intranet IP address of the ECS Instance

8

Then there you go the connection details for the Intranet will be displayed we will use this details for the Intranet connection. We will be using the connection String URI to connect. We will using the same in the next tutorial

9

Next Steps

We will create a simple Express based node API to query data for our database and serve the E-Commerce App built by leveraging the open source templates provided by the AMP Site. The whole integration will happen in the next tutorial, so please be sure to check it out.

相关实践学习
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
目录
相关文章
|
JSON 弹性计算 NoSQL
AMP for E-Commerce Part 3: Integrating the Entire Application 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.
1812 0
AMP for E-Commerce Part 3: Integrating the Entire Application with Alibaba Cloud ApsaraDB for MongoDB
|
24天前
|
运维 监控 NoSQL
【MongoDB 复制集秘籍】Secondary 同步慢怎么办?深度解析与实战指南,让你的数据库飞速同步!
【8月更文挑战第24天】本文通过一个具体案例探讨了MongoDB复制集中Secondary成员同步缓慢的问题。现象表现为数据延迟增加,影响业务运行。经分析,可能的原因包括硬件资源不足、网络状况不佳、复制日志错误等。解决策略涵盖优化硬件(如增加内存、升级CPU)、调整网络配置以减少延迟以及优化MongoDB配置(例如调整`oplogSize`、启用压缩)。通过这些方法可有效提升同步效率,保证系统的稳定性和性能。
37 4
|
28天前
|
监控 NoSQL MongoDB
MongoDB数据库的索引管理技巧
【8月更文挑战第20天】MongoDB数据库的索引管理技巧
42 1
|
28天前
|
监控 NoSQL MongoDB
mongodb数据库 使用技巧
【8月更文挑战第20天】mongodb数据库 使用技巧
34 1
|
1月前
|
JSON NoSQL Ubuntu
在Ubuntu 14.04上如何备份、恢复和迁移MongoDB数据库
在Ubuntu 14.04上如何备份、恢复和迁移MongoDB数据库
54 1
|
1月前
|
NoSQL 大数据 MongoDB
云中对决:Amazon DocumentDB 与 MongoDB的终极较量,谁将主宰云端数据库的未来?
【8月更文挑战第8天】在云计算与大数据时代,文档数据库因灵活高效备受开发者青睐。本文作为指南,全面对比Amazon DocumentDB与MongoDB。DocumentDB兼容MongoDB,便于迁移;在AWS环境下,它提供卓越的性能与自动伸缩能力。MongoDB则侧重于自定义部署与成本控制。DocumentDB作为托管服务简化管理但成本较高,而MongoDB需自行处理安全性与备份。根据需求与预算,开发者可作出最佳选择。
37 3
|
17天前
|
C# 开发者 Windows
全面指南:WPF无障碍设计从入门到精通——让每一个用户都能无障碍地享受你的应用,从自动化属性到焦点导航的最佳实践
【8月更文挑战第31天】为了确保Windows Presentation Foundation (WPF) 应用程序对所有用户都具备无障碍性,开发者需关注无障碍设计原则。这不仅是法律要求,更是社会责任,旨在让技术更人性化,惠及包括视障、听障及行动受限等用户群体。
40 0
|
17天前
|
Java 前端开发 Spring
技术融合新潮流!Vaadin携手Spring Boot、React、Angular,引领Web开发变革,你准备好了吗?
【8月更文挑战第31天】本文探讨了Vaadin与Spring Boot、React及Angular等主流技术栈的最佳融合实践。Vaadin作为现代Java Web框架,与其他技术栈结合能更好地满足复杂应用需求。文中通过示例代码展示了如何在Spring Boot项目中集成Vaadin,以及如何在Vaadin项目中使用React和Angular组件,充分发挥各技术栈的优势,提升开发效率和用户体验。开发者可根据具体需求选择合适的技术组合。
28 0
|
1月前
|
存储 NoSQL 物联网
MongoDB:改变游戏规则的数据库,看它如何统治数据世界的每一个角落
【8月更文挑战第7天】MongoDB是一款高性能、开源的NoSQL数据库,采用文档数据模型,支持丰富查询语言及二级索引。其灵活的数据模型和扩展性使其在大数据应用、实时分析、物联网、内容管理系统及电子商务平台等多种现代场景中广泛应用。例如,在大数据应用中,它可以高效存储社交媒体的非结构化数据;在实时分析中,能快速处理新数据并即时更新结果;在物联网应用中,则适用于存储大量非结构化传感器数据;而在内容管理和电子商务平台中,能提供灵活的内容存储和高效的商品搜索功能。
50 2
|
1月前
|
JSON NoSQL MongoDB
在Ubuntu 14.04上如何导入和导出MongoDB数据库
在Ubuntu 14.04上如何导入和导出MongoDB数据库
17 0