×
Community Blog Deploying a FaaS Platform for Content Delivery

Deploying a FaaS Platform for Content Delivery

In this article, we will introduce Alibaba Entertainment's function computing platform as well as their practical experience in deploying function computing.

By AliENT

1

In the Cloud Computing 2.0 era, embracing the Function as a Service (FaaS) model has become an important area of concern for developers. This is because the FaaS model can provide great value to developers in terms of efficiency, reliability, performance, and cost, and especially for R&D .

In this article, Moxun and Wusheng, technical experts from Alibaba Entertainment will introduce the design ideas and key technical challenges of Alibaba Entertainment's function computing platform as well as their practical experience in deploying function computing, using specific services as examples.

Background

Youku's content delivery service covers varopis scenarios such as the Youku host and guest homepages, channel pages, and secondary pages. It previously adopted the traditional Java application + Alibaba middleware architecture for server-side development, following a procedure of product review, API design, front-end and back-end joint debugging, and front-end and back-end releases. However, as client-side content grew increasingly diversified and products had to be iterated at a faster pace, the traditional server-side architecture development model could not keep up. Although we had developed a general framework, because the development model had not essentially changed, the costs for flexibility and development remained high. In summary, the main challenges included the large quantity of data sources that APIs depended on, the rapidly changing business requirements, and the high costs for front-end and back-end joint debugging.

As serverless technology continued to evolve, Alibaba increasingly explored FaaS and developed new practices. We considered the characteristics and challenges of FaaS in order to build up basic capabilities by introducing FaaS models. On that basis, we were able to use FaaS to handle upper-layer business logic. This is how the Youku FaaS platform designed by Alibaba Entertainment came into being.

Platform Design and Technical Challenges

Design Objectives

We wanted to implement a general-purpose function computing platform on which developers could directly write, run, and manage one or more functions that provide services. The platform was to support function calls in a variety of methods such as microservices, HTTP interfaces, and event source triggering. At the same time, the platform's function development and publishing functions needed to take effect in seconds, without the need to restart the host application. This would shorten the publishing and deployment of traditional Java applications, reduce developer's non-code development work, and enable quick rollback.

The FaaS platform needed to provide a runtime environment for functional applications and support lightweight scripting languages for function programming. Groovy is our preferred language, primarily because of its concise code and access to Java's native classes and objects.

The FaaS model needs to support the dynamic loading of function instances and resource allocation based on the actual access situation.

In summary, a function running on the FaaS platform should be a short, discrete, and reusable block of code. This would provide the following benefits:

  • A short lifecycle to support quick publishing and deployment
  • Non-daemon processes, which do not need to run for long periods and support on-demand loading
  • No persistent connection service
  • Stateless
  • Support reusing existing services or third-party resources. In particular, FaaS should be built on complete basic services.
  • Execution within milliseconds

Overall Platform Design

The overall core architecture of the FaaS platform is composed of gateways, runtime containers, the all-in-one O&M and publishing platform, and basic services.

2

The gateway layer is responsible for receiving function call requests and distributing the requests to the server environments of corresponding clusters for execution based on unique function identifiers and cluster information.

The function container layer is the core of the system, which calls and executes function instances by using a function execution engine. It also manages the lifecycle of function instances, including on-demand loading, code preloading, and instance unloading and reclamation.

The all-in-one O&M and publishing platform, namely, the FaaS Platform, is a main operating platform that allows developers to write functions, submit and release versions, roll back data, and perform monitoring and O&M. This monitoring system is connected to the basic service monitoring system of the Alibaba Cloud Group, which supports queries of basic monitoring metrics such as the real-time dashboard and cluster performance.

The entire FaaS platform is built on Alibaba Cloud Group's middleware and the various basic services that Youku relies on for content delivery. It encapsulates service calls to provide a concise service call method for developers. Meanwhile, its functions run in an isolated environment and function instances are managed in a unified manner to schedule functions, monitor execution, and manage functions dynamically.

The server-side container layer of the technology stack is implemented by using Java interfaces, and the main functions of the container layer are implemented with the help of the Alibaba Cloud Group's middleware.

The frontend is primarily implemented based on the React framework and Dva state management framework. During actual development, we chose the Bigfish framework and Odin scaffold of Ant Financial. React provides a componentized architecture, which means that the components we develop can be continuously reused like HTML basic elements in the DOM. Bigfish adopts a layered design for webpages to reuse components and improve R&D efficiency. The granularity levels from large to small are page templates > blocks > service components > components. The Odin scaffold is a front-end development scaffold released by Youku for mid-end and back-end business systems. It integrates the Bigfish framework and supports website routing in a configurable manner so that developers can quickly implement business logic and page building without paying much attention to the underlying details.

3

Similar to the Model, View, and Controller (MVC) hierarchical pattern on the server-side, the front-end implementations of business logic and data communication also follow corresponding layered designs to manage component states. After the evolution of Flux > Redux > Dva, the state management mechanism has been delivering increasingly important benefits in complex business scenarios. The complete Dva data flow is as follows.

4

State stores the overall application state, View is a view layer composed of React components, and Action is the object that describes an event. The connect method is a function that binds State to View, so that the View component can dynamically listen to the properties at the State layer and send the Action to the State layer to trigger a state change by using the dispatch method. There are two types of functions for triggering a state change, the effect function and the reducer function. The former conducts data communication with the server to handle asynchronous actions, and the latter handles synchronous actions and directly updates the state.

The frontend of the FaaS Platform consists of five modules: function creation, function management, function publishing, function templates, and application statistics. In the FaaS Platform system, a function is the smallest unit that can be scheduled by external applications, and an application is the smallest unit that server resources are divided into. Therefore, we set a one-to-many mapping between applications and functions.

5

Function Creation Module

The function creation module allows you to add functions. A complete function must include the basic information of the function, such as the name, identifier, type, application, and category in the application. Similar to the mtop (MySQL top) gateway, the module also provides the configuration pages for input parameters of the function, the responses and results, and the response error codes to automatically generate the input parameter form for function calls and the function interface document. The English identifier of a function identifies a unique function and cannot be duplicated.

Function Management Module

The function management module enables create, read, update, and delete (CRUD) operations for functions and online function compiling. You can query data with complex conditional functions and edit basic information and states of functions in this interface. The module also provides an online web IDE for compiling functions, which supports functions for adding or deleting files, coding, automatic saving, committing functions, debugging functions, and printing logs.

Function Publishing Module

The function publishing module enables queries of function submission history and function publishing. This module introduces second-party and third-party dependencies to a traditional Java application. However, unlike traditional Java application publishing, the FaaS Platform system can publish functions in seconds. Currently, the platform already supports rollback publishing and batch publishing of functions. This enables application deployment to quickly respond to complicated and changing business requirements.

Function Template Module

The function template module enables create, read, update, and delete (CRUD) operations for function templates and online function compiling. Taking actual business scenarios into account, the platform provides some basic built-in templates to speed up function initialization. You can save a function as a custom function template which can then act as a complete solution to a business problem. The web IDE for function templates supports online compiling and debugging as well as the automatic saving of function templates.

Application Statistics Module

Functions are affiliated with applications to provide server resources. Therefore, we plan to use the application statistics module to take statistics of functions for each application. The statistics cover online states of functions and published versions. Meanwhile, we also provide statistical analysis and monitoring for function calls based on function logs, such as the number of calls, the success rate, and the response time. We are gradually implementing and improving the details.

Main Features of the FaaS Platform

The main features of the Youku FaaS platform include low-cost development and access, isolation of function runtime environments, and transparency in O&M and monitoring operations.

6

Low-cost Development and Access

With the help of an all-in-one cloud development platform, the FaaS platform allows business-logic-oriented development without the need to consider basic services and middleware dependencies. The platform provides comprehensive encapsulation of basic capabilities, including quick development, quick access to middleware, quick access to data storage, and encapsulated basic capabilities for direct calls.

Its business logic development model is lightweight and application-free, and any function publishing or rollback operations take effect within seconds. This has streamlined the complicated processes during the traditional server-side development, allowing developers to concentrate on the development of core business logic.

The following development and deployment processes are designed to be concise and easy-to-operate, reducing the time costs of development and deployment.

7

In addition to the low cost of function development, the FaaS platform also features easy access to these functions. The platform supports two access modes: centralized and decentralized access. However, regardless of the access mode used, the compilation, debugging, and publishing of function code are all completed on this all-in-one O&M and publishing platform. In the centralized access mode, we utilize a unified function service cluster to provide external services, allowing callers to call functions by using a unified function calling interface, either an HSF service or an HTTP interface. In addition, the execution of function code is completely based on the function service cluster, so developers do not have to apply for applications themselves.

In the decentralized access mode, developers can reference the SDK we provide to call the FaaS functions on the platform. In this case, function execution takes place in the local process of the caller's application, and the FaaS platform only provides function development and publishing features.

Isolation of Runtime Environments

The isolation of runtime environments is divided into two levels, one being the isolation between function instances within a function container, and the other being the isolation between the virtual application clusters that functions run in.

The isolation between function instances within a function container refers to the fact that the Groovy functions written on the FaaS platform run in a unified JVM process. Each function generates multiple versions during development, and different functions and different versions of the same function are isolated in their runtime environments to prevent mutual interference.

8

Isolating clusters that run functions entails binding functions to different virtual applications upon function creation based on the functions' traffic, service characteristics (such as whether a function is a long-tail service or a general service), and other features. These applications run on different server clusters. When a function is called, the gateway layer distributes the requests to different clusters for execution based on the application that the function is bound to, ensuring physical isolation between functions.

9

Transparency in O&M and Monitoring

All functions on the FaaS platform support direct monitoring and O&M operations on the platform. We collect function execution logs during function execution processes and report the logs to the Alibaba Cloud Group's monitoring service in real time. This allows us to monitor function execution on the platform in real time.

10

Technical Challenges

Design of Function Execution Engine

The function execution engine is a core component of the FaaS platform. It is responsible for lifecycle management, such as loading, preloading, execution scheduling, and unloading of function instances. FaaS functions support the Groovy language. This is because the runtime environment provided by JVM naturally supports Groovy. On the FaaS platform, each function has its independent code version library. Each function submission generates an incremental version. When the execution engine loads a function instance, the latest version of code is loaded from the version library. Function instances are generated and added to the instance pool after initialization, precompilation, and other operations. Each function has a unique identifier. When you call a specific function, the execution engine pulls and loads the corresponding instance from the instance pool for function execution. The following figure shows the entire procedure.

11

Function instances exist in the same JVM process and are different from services in that functions feature finer granularity. Therefore, the lifecycle of functions must be strictly controlled. Otherwise, when a large number of functions are loaded into the memory, excessive memory usage may occur. The platform also supports SDK calls to prevent memory-resident functions from exhausting the host application memory. Therefore, the lazy loading mechanism has been adopted to load function instances into the memory on demand and reclaim expired instances, releasing memory and improving memory utilization.

12

Each Groovy function corresponds to a Groovy interpreter environment GroovyEngine, and different functions are independent of each other. Each function is independently precompiled and initialized when it is loaded into the memory to prevent interference between functions. At the same time, this mechanism also provides an isolated environment for loading second-party and third-party JAR packages to prevent interplay between class loaders of different functions.

13

Capabilities for Loading Second-party and Third-party JAR Packages

The FaaS platform supports loading second-party and third-party JAR packages as dependencies of functions without requiring the restart of the entire underlying container. With a Classloader that supports second-party and third-party JAR packages in Groovy, you can load second-party and third-party dependencies between functions and between function versions. The following figure shows the Classloader system of the FaaS platform.

14

Exploring the Deployment of the FaaS Platform

Currently, the business scenarios of Alibaba Entertainment are dominated by content delivery. In homepage and secondary page scenarios, content delivery requires many operational placements, response to fast changes in demand, and many data sources. The front-end and back-end joint debugging and the back-end development and deployment modes in traditional Java server-side development have resulted in significant bottlenecks, hindering iteration efficiency. In past practices, server-side development was located on the publishing pipeline before client releases, which resulted in time-consuming and costly rollback. By introducing the FaaS model, we hope to improve server-side development flexibility to let developers focus on the business logic instead of spending too much time on service deployment and maintenance.

15

Youku's internal content delivery services are primarily developed based on a unified content creation and delivery framework. This framework is orchestrated with processes to acquire content from different data sources. The content is then processed according to the business logic and output from the APIs through template field mapping. FaaS is currently primarily used when mapping data sources to templates fields. A data source is an encapsulated original data interface used to acquire the raw data required for the actual service, such as program videos, feature program data, user interest, and other business data. The template field mapping generates field values following the actual business logic by compiling Java functions. In the previous development model, you must update any business logic changes and then release the Java application for the changes to take effect. In the FaaS model, you only need to publish the corresponding FaaS function. FaaS functions can be published within seconds, so this model greatly improves iteration efficiency.

Unified Encapsulation of Data Sources

We use FaaS to encapsulate data source interfaces. A new data source interface is implemented by writing functions directly on the FaaS platform, allowing you to launch a new data source without releasing the local Java application. This is of great significance for quick access to new service interfaces. Moreover, these data sources can be reused. Therefore, implementing data sources through function reuse can greatly reduce the need for repeated development effort in a collaborative environment.

16

FaaS Function Processing Template Field Mapping in API Protocol

17

We have expanded the content creation and delivery framework. With FaaS SDKs, the template parsing phase of the server-side interface can parse both common Java functions and FaaS functions. The code of such functions is written in Groovy on the FaaS platform, instead of being written in the native Java code. You don't need to re-deploy the content distribution server-side application when compiling, updating, or publishing such functions. Instead, you only need to perform these operations on the functions on the FaaS platform. Moreover, you don't need to restart the Java application to edit field logic, allowing you to quickly respond to iterations and changes. Each function has its own lifecycle and publishing process, and the publication and changes of different functions are isolated from each other. When the field logic changes, you can directly publish the function within seconds without restarting the local Java application, which can greatly improve iteration efficiency.

Summary

FaaS capabilities have been introduced to Youku's content-delivery-related services to improve iteration efficiency. However, the platform as a whole is still in its infancy and represents only our initial attempt to implement serverless practices. We will continue to explore technologies and deployment issues related to the FaaS platform in the following areas:

  • Support the runtime environments of more programming languages and provide a more friendly cloud IDE development experience.
  • Optimize the resource scheduling policies of function execution clusters, properly allocate the resources needed for function execution, and support dynamic scaling.
  • Find more convergence with content delivery services based on service characteristics, and use FaaS to further enhance the flexibility and iteration efficiency of existing technical architectures.
0 0 0
Share on

Alibaba Clouder

2,599 posts | 764 followers

You may also like

Comments

Alibaba Clouder

2,599 posts | 764 followers

Related Products

  • Function Compute

    Alibaba Cloud Function Compute is a fully-managed event-driven compute service. It allows you to focus on writing and uploading code without the need to manage infrastructure such as servers.

    Learn More
  • Serverless Workflow

    Visualization, O&M-free orchestration, and Coordination of Stateful Application Scenarios

    Learn More
  • Serverless Application Engine

    Serverless Application Engine (SAE) is the world's first application-oriented serverless PaaS, providing a cost-effective and highly efficient one-stop application hosting solution.

    Learn More
  • CDN(Alibaba Cloud CDN)

    A scalable and high-performance content delivery service for accelerated distribution of content to users across the globe

    Learn More