Web application

Static websites with CDN and OSS

Static websites are websites where all web pages consist of only static content, including scripts such as JavaScript code running on the client.

A static website can be hosted on Alibaba Cloud Object Storage Service (OSS) and accelerated by CDN.

FCkehuanliqwee123
Here are some of the benefits of hosting website with OSS:
  1. Operations and Maintenance (O&M) free: You do not need to manage servers, such as patching OS, maintaining high availability of the site.
  2. Scalability: there is no need to estimate resources and think about future extensibility. Because OSS itself is elastic, using CDN makes the system even cheaper, faster, and improves the availability.
  3. Cost: The fee is paid based on the resources that's actually used, including storage fee and request fee. No request fee is charged if there is no request.
  4. Security: There is no server exposed to the outside and no one can SSH to the site. DDoS attacks are also took care of by cloud services.

Further readings: Deploying Static Websites Using OSS and CDN on Alibaba Cloud.

On-the-fly image processing with FC

Alternatively, static websites can be hosted on Alibaba Cloud Function Compute service. Since Function Compute is general purpose compute service, you can run a web server as function to serve the static content. For example, frameworks like hexo and gatsby can generate static files, or run in server mode. This is not a common pattern, but thanks to the integration between CDN and Function Compute, it's also cost-effective, scalable, secure, and highly available.

A common usage of this pattern is to serve images that require on-the-fly processing.kehuanlifc1122
The reference architecture works as below:
  1. Client requests an image, if CDN has not cached the requested image, it forwards the request to the function (origin).
  2. The function gets image from OSS, does some processing, and returns the result to CDN.
  3. CDN caches the result and returns the image to the client.
The advantage of this architecture:
  1. Efficient payload: Unlike most other FaaS platforms which only support JSON format event, the HTTP trigger passes through the event directly to the HTTP function without any transformation, and the function response is also passed back without any transformation. It's very efficient to handle any event format, e.g. image format, protocol buffer, cbor, xml.
  2. No API Gateway related complexity, latency and cost.

Use cases:

Sina Weibo stored the image files uploaded by users to Alibaba Cloud OSS, and wrote functions for customized image file processing. When a Sina Weibo user requests to access an image file through a client, the access request is sent back to Function Compute through Alibaba Cloud CDN. Then, the related function downloads the source image file from OSS, processes the image file as required based on the client type, and then returns the processed image file to the user.

API backend

In building applications, an API simplifies programming by abstracting the underlying implementation and only exposing objects or actions the developer needs. The Alibaba Cloud Function Compute, integrating with other services, provides a variety of ways to expose functions as APIs to serve different purpose.kehuanlifa098
  1. The service exposes InvokeFunctions API.
  2. API Gateway provides a variety of security mechanisms and can work with Web Application Firewall (WAF), Anti-DDoS Pro, and Identity as a Service (IDaaS) to build a full-link API security protection system. The security mechanisms it offers include API authentication, parameter cleansing, full-link signature verification, CA certificate verification, access control, throttling, and access over an internal network.
  3. Built-in HTTP trigger. This is a convenient, efficient way to expose functions as there is no extra service between the client and function. The request payload is directly passed to the function and the response is passed back to client without any transformation.
  4. Alibaba Cloud CDN supports using FC function as origin server. Sina weibo uses this approach to do on-the-fly image processing for every image that's posted to weibo.
  5. Mobile gateway helps build mobile apps by providing full development cycle support, such as generating SDKs from APIs.

Event driven application

Fan-out

In message-oriented middleware solutions, fan-out is a messaging pattern used to model an information exchange that implies the delivery (or spreading) of a message to one or multiple destinations possibly in parallel, and not halting the process that executes the messaging to wait for any response to that message.

Traditionally, an application does its business logic first and then publishes the message to a event hub which is listened by some other applications. Alibaba Cloud serverless offerings make implementing this pattern much simpler by providing native integrations among services.

The below reference architecture uses Function Compute and EventBridge service.kehuanli34567fc
  • A destination can be configured for a function. If the result of the asynchronous invocation meets the condition (failure or success), Function Compute sends the context and data of the asynchronous invocation to the specified service. This allows cloud services to interact with each other. You can configure different destinations for different functions, aliases, and versions. The following destination services for asynchronous invocation are supported: MNS queue, MNS topic, Function Compute, EventBridge. See Manage asynchronous invocation configurations for more details.
  • EventBridge filters events by using event patterns and then routes events to event targets, see Route events to Function Compute for more details.
The reference architecture works as below:
  1. Configure function with EventBridge as destination.
  2. Configure EventBridge rules to route events to different targes, e.g. another function, email, sms.
  3. Once the function execution is completed, Function Compute service sends the result to EventBridge.
  4. EventBridge routes the events to different targets based on the configured rules.

Fan-out/in

Another way to implement the fan-out pattern is to use an orchestration service. In addition to support the fan-out pattern, orchestration service is also great at supporting the fan-in pattern.

The below reference architecture uses Serverless Workflow and Function Compute to process large video files.kehuanlifc890
The reference architecture works as below:
  1. The split function downloads the video from OSS, splits the video into multiple parts and stores them to NAS.
  2. The workflow uses Foreach step to run multiple functions to transcode the individual parts.
  3. The merge function merges the individual parts together and stores the result back to OSS.
  4. The post-process function deletes the video from NAS and refreshes the CDN cache.

CQRS

The Command and Query Responsibility Segregation (CQRS) pattern separates read and update operations. Implementing CQRS in your application can maximize its performance, scalability, and security.

For example, NoSQL database like Alibaba Cloud Tablestore provides high availability and scalability for read and update operations, but its query capability is limited comparing to relational databases. Using the CQRS pattern can bring the best parts of NoSQL and SQL databases.

The below reference architecture uses Function Compute, Tablestore and RDS service.kehuanline67890

Tablestore Stream is a data channel used to obtain incremental data in Tablestore tables. By creating Tablestore triggers, functions can consume incremental changes to the table.

The reference architecture works as below:
  1. The command function writes data to a table in Tablestore.
  2. The table stream is consumed by a processor function which writes some columns to a table in RDS.
  3. The query function queries data from the RDS table.

Data processing

Real-time file processing

The below reference architecture uses Function Compute and OSS to process files in real-time.

buhuokehuanlifc
The reference architecture works as below:
  1. User uploads a file to OSS.
  2. OSS invokes function with event containing the file and request info.
  3. The function downloads the file, processes the file and stores the file back to OSS.