Alibaba Midway Serverless v1.0: let’s building Serverless cloud ecosystem with Node.js
Github: https://github.com/midwayjs/midway, open source project for the development of front-end and Node.js developers, come to Github and click Star!
In the past six months, Midway FaaS has attracted the attention of many students, and many large enterprises have started to use it directly. Thank you here. Today, Midway FaaS will evolve into Midway Serverless and release v1.0 officially.
v1.0 represents a formal version and can be reliabe. Through the new Midway Serverless architecture, we have gradually opened Alibaba’s Serverless capabilities, and the front-end devs will come to next generation. As story started two years ago, open source of Midway is just the beginning, and we haven’t reach the final state.
The Serverless today has came to it’s golden age for cloud vendors to explore their own territory. It’s also the best timing for us to try. Nowadays, Node.js has became the best way leads to serverless, and the Midwayjs also stood at this crossroad trying to lead the direction.
What is Midway Serverless
As this post mentioned, Midway Serverless is a Serverless-oriented solution, which includes framework, runtime, tool chain, and configuration specifications. With these combination, it provides some special capabilities for Serverless systems:
- Migration between platforms came easier
- By providing unified configuration specification and entry Leveling mechanism, the code is almost the same on each platform.
- Extending Runtime APIs of different cloud platforms. Not only to load common inter-platform extensions, but also access private deployment solutions on-premise.
2. Make applications easier to maintain and scale
- TypeScript is used as the basic language to the extension and definition.
- It provides a complete DI (dependency injection) solution.
- Provides standard definition of events for functions on the cloud platform.
- It provides various integrated solutions with React, Vue, etc.
3. More flexible and lightweight ecosystem
- The function coding can reuse koa’s ecosystem and Web middlewares, which ma’ke it more handy when dealing with Web projets.
- It inherits the ecosystem from the eggjs which means we can reuse the it’s plug-in, that makes the enterprise-level development simpler and smoother.
- The decorator of the Midwayjs has unified, making it faster and better to migrate traditional Web to the Serverless architecture.
All the capabilities mentioned above have been open-source in Midway Serverless repo. Welcome to Star.
Serverless and FaaS
FaaS is one of the forms of the Serverless architecture and is also the scenario that Midwayjs wants to help. Before v1.0, we got a lot work with FaaS, but in fact the Serverless architecture is very large, FaaS is only a small part of it, based on event-driven models, from MicroService, a small function block that focuses on a single responsibility and function. Now This software architecture paradigm with more “code snippets” provide unparalleled flexibility for business code compared with smaller program units of microservices.
Today, according to the statistics of Forbes magazine, typical servers in commercial and enterprise data centers only provide 5% ~ 15% of the output of the average maximum processing capacity, this is undoubtedly a huge waste of resources. With the emergence of Serverless architecture, service providers can provide our computing power to meet real-time requirements to the greatest extent, which will enable us to use computing resources more effectively.
Elastic containers can meet all current expectations for resource utilization, and are also one of the goals that cloud platforms are constantly pursuing. For developers, whether they are elastic containers or elastic functions, as long as a set of code can be run to meet business needs. The goal of Midway Serverless is to expand from the original FaaS scenario to other fields. Whether it is a function or a new architecture, we will meet the requirements one by one, and implement the business and feedback the community.
Avoid vendor lock-in
Vendor Lock-in is a question that everyone who uses the cloud platform would ask. The original intention of Midway Serverless is Enable a set of code to run on different platforms and runtime , we do not recommend customizing a runtime to fit all the platform while we can’t enumerate all platform, which means incompatibility. In fact, the official runtime of each platforms is the most stable and have the best performance.
The first problem for most enterprises that we know about Serverless is that my code is not necessarily stay at Alibaba Cloud, Tencent Cloud or AWS etc.
To solve this problem, Midway Serverless provides a set of implicit portals and general definitions to solve this problem.
For each platform, Midway Serverless provides different runtime initiators to smooth the differences between different platforms. Through these initiators, the input and output parameters of each platform, as well as the structure of each event, the response format of the Gateway is regularized to prevent users from perceiving the differences between the underlying containers and protocols as much as possible.
In addition, Midway Serverless provides a set of Spec definitions to smooth the differences between multiple platforms. At the same time, it is also convenient to reuse the same tool chain and function logic among multiple platforms.
In this way, both API Gateway and common HTTP triggers can provide APIs in a unified programming plane, making it easy to write code.
TS and decorator
The function writing is very flexible, which brings convenience and additional maintenance cost. Therefore, Typescript, serverless standards and scalability are introduced.
The following code seems to be the standard syntax of koa. In fact, it is an HTTP trigger-oriented API in a function. In order to be consistent with the Web stack syntax, some changes have been made to obtain parameters, calls are seamlessly connected as much as possible, reducing the cost of learning and migrating the original code better.
On the other hand, the method with decorators will become a function entry, making the structure of the function become flexible. By the build step of CLI, the real entry is hidden, which not only allows functions to be called across multiple platforms, but also can be adapted to different routes. As shown in the above example, there are multiple entries in a file, you can Share the same code , but in fact Each function is called independently , providing convenience in management and post-maintenance.
The actual structure of different cloud platforms is different. If you need to use traditional event and context structures, we also provide different definitions for different platform triggers to facilitate code writing, as shown in the following gif:
Community ecosystem reuse
As this post mentioned above, the original motivation of Midway Serverless is to reuse the existing koa ecosystem and make the underlying event rules of multiple platforms into a unified koa-like API. APIs are similar for the entire koa web ecosystem. We also hope that The middleware ecosystem of koa can be reused . As shown in the following figure, introduced
On the other hand, according the IoC (Inversion of Control) ability, Midwayjs provides the basis of egg, and at the same time, can also reuse existing egg plug-ins, so that the traditional enterprise-level development capabilities can be continued, as shown in the following the example of the
Full-stack experience for frond-end developers
The development experience of the Cloud + End is one of the goals of Midway Serverless. For the development of traditional applications, the front-end and back-end are separated, multi repo development and deployment are separated. Though we use Node.js as the glue layer, it still cannot avoid the split of the sense of the development of personnel. But this is not a problem in the Serverless architecture.
Due to the large simplification of the backend and The BaaS of cloud services, it’s easier to data aggregation and page rendering, and the front-end can be started quickly and developed faster.
Integration gradually becoming the front-end demand of this area, this is not only the integration of multi repo to monorepo, but also the evolution of the entire development mode, from the engineering system + code, the opportunity to reshape the CI/CD system.
Today’s Midway Serverless, Provides a development solution integrated with the front-end , including the existing React and Vue ecosystems in the community, and customized solutions for the entire tool chain (Webpack,ice scrips,umi, etc.). For different scenarios, for example, blogs and so on also provide out-of-the-box solutions.
As for the detailed front-end and back-end integration capabilities, we will open a separate article to introduce the details and thinking of front-end integration.
Application and Function
Serverless architecture is the direction for a period of time in the future, and is also the Paving Wall for the front-end to move towards a higher level.
We have been thinking about the relationship between the final state of functional development and the application?
At this stage, our answer is that it tends to be unified. We have been asked for countless times about the future and users’ demand. We think that functions are the smallest embodiment of applications in the current business, more simply, it is in Minimum specification container Running in Application The Part Code.
In the following period of time, we will focus on the access of more platforms and the migration scheme of traditional applications, so that previous users can also enjoy the bonus of Serverless flexibility and lower enterprise costs, it is easier to launch the projects.
With the deepening of the larger services, smaller portable front-end business architecture, and the development of the Alibaba Group’s cloud-native/Serverless last year. We saw the future in the massive end-to-end business delivery scenario with Node.js.
The new generation of Cloud + End front-end business delivery mode has gradually become a reality, which can help the technical team to shape special forces with overall business delivery capability and help the business win quickly. But there are still many barriers in this way. In order to achieve this step as soon as possible, we need to focus highly on two core issues: 1. Scale cost, 2. Delivery speed.
We hope that the Node.js/Serverless system can show all-round advancement through our continuous investment in scale costs and delivery speeds in the future.