Coursera 笔记

Module 06 · Final Project and Assignment最终项目与作业

Case Study: Modernize a Food Delivery Service with Cloud案例研究:利用云计算现代化食品配送服务

Coursera ↗

Estimated time needed: 30 minutes
所需估计时间:30 分钟

DineEase

DineEase is a food ordering system that offers a mobile application for end-users (consumers) and a web application for back-office and administrative users. Consumers can order food from any number of restaurants. The system locates the consumer's selected restaurant, sends the order to the restaurant, collects money from the consumer, and disburses the consumers payments to the restaurant and the delivery person.
DineEase 是一个提供面向最终用户(消费者)的移动应用程序和面向后台办公室及管理用户的 Web 应用程序的订餐系统。消费者可以从任意数量的餐厅订购食物。该系统定位消费者选择的餐厅,将订单发送至餐厅,从消费者处收取款项,并将消费者的付款分配给餐厅和送餐员。

Your mission for this project is to assist with moving the legacy DineEase platform, built on top of a monolith architecture, to a Cloud Native architecture built on microservices. After evaluating several Cloud providers, DineEase chose IBM Cloud to deploy the revamped platform. As part of the project, you will become familiar with the current platform components. Then, you will provide recommendations for the IBM Cloud services that are most suitable for DineEases' new Cloud Native deployment.
您的任务是协助将基于单体架构构建的 DineEase 平台迁移到基于微服务的云原生架构。在评估了多家云服务提供商后,DineEase 选择了 IBM Cloud 来部署改进后的平台。作为项目的一部分,您将熟悉当前平台组件。然后,您将为 DineEase 的新云原生部署提供最适合的 IBM Cloud 服务建议。

DineEase platform components DineEase 平台组件

DineEase has several components (modules) including:
DineEase 包含多个组件(模块),包括:

A module serves the menu details of a restaurant. This module interacts with the database to access, retrieve, and manage information about menu items and their categories. Common functions include:
一个模块负责餐厅的菜单详情。此模块与数据库交互,以访问、检索和管理关于菜单项及其类别的信息。常见功能包括:

  • Get Menu Items: Retrieve a list of all items available on the menu, including their names, descriptions, prices, and images.
    获取菜单项:检索菜单上所有可用的项目列表,包括它们的名称、描述、价格和图片。
  • Get Menu Categories: Retrieve a list of menu categories (such as appetizers, main courses, desserts) to organize food items.
    获取菜单分类:检索菜单分类列表(如开胃菜、主菜、甜点)以组织食品项目。
  • Filter by Category: Retrieve menu items specific to a particular category.
    按类别筛选:检索特定类别的菜单项。

Pricing 定价

A module provides dynamic pricing based on customer location, previous order history, public holidays, weekends, or an event. It provides a centralized platform to manage and update pricing for all menu items and services. This pricing module allows restaurant owners to make changes in one place and have those updates reflected across all connected systems in real-time.
一个模块根据客户位置、历史订单、公共假日、周末或活动提供动态定价。它提供了一个集中平台来管理和更新所有菜单项和服务的定价。此定价模块允许餐厅业主在一个地方进行更改,并且这些更新会实时反映在所有连接系统中。

Ordering 订餐

A module that accepts orders placed by customers. This module is a critical component that handles taking and managing customer orders. The module enables restaurants to efficiently manage incoming orders, ensure accurate preparation and delivery, and provide a seamless ordering experience for consumers.
一个接受客户订单的模块。该模块是处理和管理客户订单的关键组件。该模块使餐厅能够高效地管理 incoming orders,确保准确准备和交付,并为消费者提供无缝的订餐体验。

Payment 支付

A module takes pricing and ordering details and charges the payment method. And the process all happens securely, building consumer confidence. This module accepts multiple payment methods and seamlessly integrates with Point of Sales (POS) systems.
一个模块接收定价和订单详情,并对支付方式进行收费。整个过程都在安全的环境中进行,从而建立消费者的信心。此模块接受多种支付方式,并与销售点(POS)系统无缝集成。

Dispatch 派遣

A module that passes the customer order details to restaurants so restaurants can start cooking and arrange delivery to the customer. Meanwhile, align the delivery partner, ensuring that customers are not waiting too long before the food is ready and that delivery people are not turning up too late after the food is ready. This module also provides real time tracking, so the consumers know when their food will be at their door.
一个将客户订单详情传递给餐厅的模块,以便餐厅可以开始烹饪并安排送货给客户。同时,协调配送伙伴,确保客户在食物准备好之前不会等待太久,以及食物准备好后配送人员不会迟到。此模块还提供实时跟踪,让消费者知道他们的食物何时会送到门口。

DineEase database DineEase 数据库

All of the DineEase data is stored in self-managed relational database. Complex relationships are defined between entities.
所有 DineEase 数据存储在自管理的数据库中。实体之间定义了复杂的关系。

Relational database 关系数据库

A relational database is a database management system (DBMS) that stores and organizes data in a structured format using tables, rows, and columns. Relational databases are based on the relational model, introduced by Dr. E.F. Codd in 1970. In a relational database, data is represented in the form of tables, and the relationships between different tables are established using keys.
关系数据库是一种数据库管理系统(DBMS),它使用表格、行和列以结构化格式存储和组织数据。关系数据库基于 1970 年由科德博士提出的关联模型。在关系数据库中,数据以表格形式表示,不同表格之间的关系通过键来建立。

The relational model provides several advantages, including data integrity, data consistency, and the ability to perform complex queries using Structured Query Language (SQL).
关系模型提供了多个优势,包括数据完整性、数据一致性和使用结构化查询语言(SQL)执行复杂查询的能力。

For example, a restaurant has a menu with multiple items listed. Each menu item has an associated price, and the database must store multiple rows to allow changes based on the price list.
例如,一家餐厅有一份包含多个项目的菜单。每个菜单项都有一个相应的价格,数据库必须存储多行以允许根据价格表进行更改。

Key components of a relational database include:
关系型数据库的关键组件包括:

  • Table: A table is a collection of related data organized into rows and columns. Each row in the table represents a single record or data entry, while each column represents a specific attribute or field for that record.
    表:表是由行和列组织的相关数据的集合。表中的每一行代表一个单独的记录或数据条目,而每一列代表该记录的特定属性或字段。
  • Row: A row represents a single instance of data in a table. A row contains values for each column, representing the attributes of that particular record.
    行:行表示表中数据的一个实例。行包含每列的值,代表该特定记录的属性。
  • Column: Also known as a field, a column represents a specific attribute or data type shared by all rows in the table. Each column has a unique name that identifies its purpose.
    列:也称为字段,列表示表中所有行共享的特定属性或数据类型。每个列都有一个唯一名称,用于标识其用途。
  • Relationships: Relationships in a relational database define how data in different tables are related or connected. Hence the name, relational database.
    关系:关系数据库中的关系定义了不同表中的数据是如何相互关联或连接的。因此得名关系数据库。

Monolith challenges 单体挑战

DineEase was built as a monolith application and deployed on servers manually. But the recent demand has highlighted some challenges with that architecture. Your task is to make the application Cloud-ready.
DineEase 是一个单体应用程序,手动部署在服务器上。但最近的需求凸显了该架构的一些挑战。您的任务是使应用程序云就绪。

  • Scalability: Unable to scale certain parts of the platform. For example, the Ordering service on its own can not be scaled to meet demands in certain countries on special events. For example Super Bowl in the US, Olympic Games ceremony.
    可扩展性:无法扩展平台的部分功能。例如,订单服务本身无法扩展以满足某些国家在特殊事件的需求。例如美国的超级碗、奥运会开幕式。
  • Low latency and high availability: Dispatch service depends on regional players but with monolith design, it is difficult to target high availability without too much overhead.
    低延迟和高可用性:调度服务依赖于区域玩家,但采用单体设计,在不增加过多开销的情况下难以实现高可用性。
  • Dedicated workload: The Payments part of the architecture requires real-time processing and computation of fraud checks. But it cannot be scaled on its own.
    专用工作负载:架构中的支付部分需要实时处理和计算欺诈检查。但它本身无法进行扩展。
  • Only API: Search, Menu and Pricing can be converted to API services, so that these services can be accessed from different channels.
    仅 API:搜索、菜单和定价可以转换为 API 服务,以便这些服务可以从不同的渠道访问。
  • Improve read performance: Before placing an order, customers like to see a restaurant's latest ratings and reviews. Joining data from Restaurant, Review and Rating tables is proving to be difficult with the growth in number of restaurants and users.
    提高阅读性能:在下单之前,顾客喜欢查看餐厅最新的评分和评论。随着餐厅和用户数量的增长,从餐厅、评论和评分表中整合数据正变得越来越困难。
  • Regional databases: Having a single self-managed global database is proving to be difficult and creates unwanted limitations.
    区域数据库:拥有一个单一的自管理全球数据库正变得越来越困难,并产生了不希望的限制。

DineEase 2.0

What are Microservices? 什么是微服务?

Microservices (or microservices architecture) is a cloud-native architectural approach in which a single application is composed of many loosely coupled and independently deployable smaller components or services. These services typically:
微服务(或微服务架构)是一种云原生架构方法,其中单个应用程序由许多松散耦合且可独立部署的较小组件或服务组成。这些服务通常:

  • Have their own technology stack, inclusive of the database and data management model;
    拥有自己的技术栈,包括数据库和数据管理模型;
  • Communicate with one another over a combination of REST APIs, event streaming, and message brokers; and
    通过 REST API、事件流和消息代理的组合进行相互通信;
  • Are organized by business capability, with the line separating services referred to as a bounded context.
    由业务能力组织,服务之间的界限称为边界上下文。

Read more about Microservices.
了解更多关于微服务的内容。

1. Provide low latency and high availability 提供低延迟和高可用性

DineEase wants to benefit from regional deployment of services; so it can provide low latency access to delivery partners for dispatch services. These services provide real time updates of orders to both customer and delivery partner, tell delivery partners when it's ready to be collected, and show journey and estimated time of arrival (ETA) to the customer.
DineEase 希望从服务的区域部署中获益;因此,它可以向配送合作伙伴提供低延迟的调度服务访问。这些服务向客户和配送合作伙伴提供订单的实时更新,告知配送合作伙伴何时可以取货,并向客户展示行程和预计到达时间(ETA)。

The availability requirement for these services is 99.99%, and they should use separate physical locations within a region to prevent failures on data center outages.
这些服务的可用性要求为 99.99%,并且应在区域内使用不同的物理位置,以防止数据中心故障导致服务中断。

Task 1: Visit IBM Cloud Regions and identify which regional deployment setup will suit this need.
任务 1:访问 IBM 云区域,并确定哪种区域部署设置符合这一需求。

2. Run dedicated workloads 2. 运行专用工作负载

Payment processing for DineEase is computationally intensive, needs a secure environment, and has to process large amounts of data very quickly, so there are no delays in payment processing and fraud checks.
DineEase 的支付处理计算密集,需要安全的环境,并且必须非常快速地处理大量数据,因此支付处理和欺诈检查没有延迟。

For this kind of workload, you need services that provide direct access to the underlying physical hardware, eliminate the overhead associated with virtualization, and have dedicated access to the entire physical server without sharing any RAM or CPU resources with other tenants and can also provide a graphics processing unit (GPU) to power the performance where the CPU lacks power.
对于这种工作负载,您需要提供直接访问底层物理硬件的服务,消除与虚拟化相关的开销,并能够获得对整个物理服务器的专用访问权限,无需与其他租户共享任何 RAM 或 CPU 资源,还可以提供图形处理单元(GPU),以弥补 CPU 性能不足的地方。

Task 2: Visit Compute solutions on IBM Cloud and identify which compute service offers the capabilities needed for running a dedicated workload as mentioned above.
任务 2:访问 IBM 云上的 Compute solutions,确定哪种计算服务提供上述所需运行专用工作负载的功能。

3. Use API services 3. 使用 API 服务

Search, Menu, and Pricing services for DineEase need the flexibility of using different technology stacks per service, avoiding the hassle of setting up individual servers for each service. These services must have individual development and deployment life cycles and be able to run on hosts with different operating systems.
搜索、菜单和定价服务对于 DineEase 需要根据每个服务使用不同技术栈的灵活性,避免为每个服务设置单独服务器的麻烦。这些服务必须拥有独立的发展和部署生命周期,并且能够在不同操作系统的主机上运行。

These services will run code in response to HTTP-based API requests from mobile applications, third-party services, or from interacting with each other, and these services must be lightweight and portable.
这些服务将对来自移动应用、第三方服务或相互交互的基于 HTTP 的 API 请求执行代码,并且这些服务必须是轻量级和可移植的。

Task 3: Visit Containers on IBM Cloud and identify computer services that offer the capabilities needed for running a flexible set of services that can scale automatically and independently and are self-healing.
任务 3:访问 IBM 云上的容器,并识别提供所需能力的计算机服务,这些服务能够运行可灵活扩展且可自动独立扩展的自修复服务。

To also provide the capability to interact among these services or from the outside world and remove rigid dependency on each other, you need to add a layer of communication in between.
为了也能提供这些服务之间或从外部世界进行交互的能力,并消除对彼此的刚性依赖,需要在它们之间添加一层通信层。

This component should also provide request routing, which consults a routing map that shows where each request should be sent.
该组件还应提供请求路由功能,该功能将参考一个路由图,显示每个请求应发送到何处。

4. Identify the right gateway 4. 确定正确的网关

Task 4: Visit Gateways on IBM Cloud and identify the right type of gateway needed to provide this layer.
任务 4:访问 IBM 云中的网关,并确定提供此层所需的正确类型的网关。

5. Improve read performance 5. 提高读取性能

Providing optimized reads to let consumers see reviews and ratings of a restaurant has been challenging. Because the platform is growing, this is becoming difficult to maintain due to the growth in data sizes.
为消费者提供优化的阅读内容,让他们查看餐厅的评论和评分一直具有挑战性。由于平台正在增长,数据规模的增加使得维护变得越来越困难。

To support this growth, developers decided to bring in a document database to enhance read performance, and avoid complex joins on relational databases, but still keep the capability of complex queries for Reviews of a restaurant.
为了支持这种增长,开发者决定引入文档数据库以增强读取性能,并避免在关系数据库上进行复杂的连接操作,但仍然保留对餐厅评论进行复杂查询的能力。

The schema of this temporal data must be flexible to accommodate unstructured data.
该时序数据的架构必须灵活,以适应非结构化数据。

Use document-based databases 基于文档的数据库

A document-based database is a type of NoSQL (Not Only SQL) database that stores and manages data in the form of documents. In this context, a document refers to a self-contained, hierarchical data structure typically represented in formats like JSON (JavaScript Object Notation) or BSON (Binary JSON). These documents can vary in structure and can have nested fields, making them flexible for storing different types of data.
基于文档的数据库是一种 NoSQL(非 SQL)数据库,它以文档的形式存储和管理数据。在此语境中,文档指的是一种自包含的、层次化的数据结构,通常以 JSON(JavaScript 对象表示法)或 BSON(二进制 JSON)等格式表示。这些文档的结构可能不同,可以包含嵌套字段,这使得它们能够灵活地存储不同类型的数据。

Unlike traditional relational databases, which store data in tables with predefined schemas, document-based databases allow for schema flexibility.
与传统的基于表的关系数据库不同,后者以预定义的模式存储数据,文档型数据库允许模式灵活性。

restaurant = {
    id: "Yb5xwX",
    name: "Flavors & Tales",
    latestReviews: [
        { at:ISODate("2023-07-01T16:22:01.090Z"), text: "Wow! F&T has won my heart with their mouthwatering dishes." },
        { at:ISODate("2023-06-24T21:02:54.989Z"), text: "The Smoky Ribs were fall-off-the-bone tender, and the BBQ sauce was finger-licking good." }
    ],
    starRatings:{
        totalRatings: 34,
        stars: [9, 20, 5, 0, 0],
        average: 4.1
    }
}

Task 5: Visit the IBM Cloud database options and identify a document-based database that deploys and scales instantly to meet requirements and provides built-in offline-first architecture.
任务 5:访问 IBM 云数据库选项,并识别一种基于文档的数据库,该数据库能够即时部署和扩展以满足需求,并提供内置的离线优先架构。

6. Ease transactional database administration 6. 便捷的事务型数据库管理

So far DineEase has managed to run its ordering system on a self-managed relational database to satisfy its data demands. But this requires too much operational overhead to administer the database and is proving difficult every time additional capacity needs to be added. Now you are ready to harness the Cloud by using a managed database service that can automatically scale capacity.
截至目前,DineEase 已成功在其自管理的数据库上运行其订单系统,以满足其数据需求。但这需要过多的运营开销来管理数据库,并且每次需要增加额外容量时都证明是困难的。现在,您已经准备好通过使用可以自动扩展容量的托管数据库服务来利用云服务。

The key requirements are:
关键要求是:

  • The new service has to be fully managed by the provider
    新服务必须由提供商全面管理
  • Should provide high-availability disaster recovery (HADR)
    应提供高可用性灾难恢复(HADR)
  • Still a relational database
    仍然是一个关系型数据库
  • Delivers fast query processing with enterprise-level performance
    提供具有企业级性能的快速查询处理
  • Capabilities for online transactional processing
    在线事务处理能力

Task 6: Visit IBM Cloud Database and identify a relational database that satisfies the preceding criteria.
任务 6:访问 IBM 云数据库,并识别一个满足先前标准的数据库。

7. Distribute media quickly 7. 快速分发媒体

DineEase hosts a lot of food photos, restaurant logos, and other secondary media. Currently, these photos are served by the same web host that serves the monolith web application. After the new design moves away from the monolith, you will still need to provide a mechanism that hosts this media. The tool that provides such capability helps with reducing latency by distributing across multiple geographic locations, bringing content closer to consumers, reducing the workload on the web server by hosting static content and saving bandwidth by leveraging compression and caching. The tool can also adapt the content to the consumer's device type.
DineEase 托管了大量的食物照片、餐厅标志和其他辅助媒体。目前,这些照片由与单体 Web 应用程序相同的 Web 主机提供服务。在新设计摆脱单体架构后,您仍然需要提供托管这些媒体的手段。提供这种功能的工具通过跨多个地理位置分布,将内容更靠近消费者,通过托管静态内容减轻 Web 服务器的负担,并通过利用压缩和缓存节省带宽来降低延迟。该工具还可以根据消费者的设备类型调整内容。

Task 7: Visit [IBM Cloud Catalog Networking products](Content Delivery Network “IBM Cloud Catalog Networking products”) and find the service that distributes your content in geographically diverse nodes, shortens the distance the content must travel to get to your end user, takes advantage of superior web and mobile performance, and provides content delivery solutions.
任务 7:访问[IBM 云目录网络产品](内容分发网络 “IBM 云目录网络产品”),找到在地理上分布广泛的节点中分发您的内容、缩短内容到达终端用户距离、利用卓越的网页和移动性能,并提供内容分发解决方案的服务。

Operations 2.0 操作 2.0

8. Increase uptime and availability 8. 提高正常运行时间和可用性

Now that each functional part of DineEase is divided into dedicated microservices, next consider how the load can be distributed amongst multiple instances. This service should provide us with high availability by distributing incoming traffic across multiple instances evenly, can provide fault tolerance when it detects failures, and provides a central point to access a “type” of resource, for example, menu service.
现在 DineEase 的每个功能部分都已划分为专门的微服务,接下来考虑如何将负载分配到多个实例。此服务应通过在多个实例之间均匀分配传入流量来提供高可用性,在检测到故障时提供容错性,并提供访问“类型”资源的中心点,例如菜单服务。

Task 8: Visit Cloud Networking Solutions and find a service that you can use to balance traffic among your servers to help improve uptime. And can easily scale your applications by adding or removing servers with minimal disruption to your traffic flows.
任务 8:访问云网络解决方案,寻找一个可以帮助您在服务器之间平衡流量以提高系统稳定性的服务。并且可以通过添加或移除服务器来轻松扩展您的应用程序,对流量流动的影响最小。

9. Perform health monitoring 9. 执行健康监控

With the introduction of new cloud technologies, you need to be equipped with the right tools and solutions to keep operations running.
随着新云技术的引入,您需要配备正确的工具和解决方案以保持运营。

Task 9: Visit Monitoring on IBM Cloud and locate a cloud-native management system you can include as part of your IBM Cloud architecture that provides you with operational visibility into the performance and health of your applications, services, and platforms. This system must also support monitoring and troubleshooting, the definition of alerts, and the creation of custom dashboards.
任务 9:访问 IBM 云的监控,找到您可以将其作为 IBM 云架构一部分的云原生管理系统。该系统应为您提供对应用程序、服务和平台性能和健康状况的操作可见性。此系统还必须支持监控和故障排除、警报定义以及自定义仪表板的创建。

Conclusion 结论

Congratulations, you defined the key components needed for the DineEase architecture in the Cloud!
恭喜您,您已定义了 DineEase 架构在云中所需的关键组件!

Author(s) 作者(们)

Muhammad Yahya  穆罕默德·亚哈亚