Static websites with CDN and OSS
- Operations and Maintenance (O&M) free: You do not need to manage servers, such as patching OS, maintaining high availability of the site.
- 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.
- 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.
- 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.
- Client requests an image, if CDN has not cached the requested image, it forwards the request to the function (origin).
- The function gets image from OSS, does some processing, and returns the result to CDN.
- CDN caches the result and returns the image to the client.
- 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.
- No API Gateway related complexity, latency and cost.
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.
- The service exposes InvokeFunctions API.
- 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.
- 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.
- 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.
- Mobile gateway helps build mobile apps by providing full development cycle support, such as generating SDKs from APIs.
Event driven application
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.
- 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.
- Configure function with EventBridge as destination.
- Configure EventBridge rules to route events to different targes, e.g. another function, email, sms.
- Once the function execution is completed, Function Compute service sends the result to EventBridge.
- EventBridge routes the events to different targets based on the configured rules.
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 split function downloads the video from OSS, splits the video into multiple parts and stores them to NAS.
- The workflow uses Foreach step to run multiple functions to transcode the individual parts.
- The merge function merges the individual parts together and stores the result back to OSS.
- The post-process function deletes the video from NAS and refreshes the CDN cache.
- Build an audio and video processing system with elasticity and high availability based on Serverless architecture
- Yuque uses Function Compute to process video files.
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.
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 command function writes data to a table in Tablestore.
- The table stream is consumed by a processor function which writes some columns to a table in RDS.
- The query function queries data from the RDS table.
Real-time file processing
The below reference architecture uses Function Compute and OSS to process files in real-time.
- User uploads a file to OSS.
- OSS invokes function with event containing the file and request info.
- The function downloads the file, processes the file and stores the file back to OSS.