Scalable Serverless APIs on Alibaba Cloud

By Afzaal Ahmad Zeeshan, Alibaba Cloud Tech Share Author. Tech Share is Alibaba Cloud’s incentive program to encourage the sharing of technical knowledge and best practices within the cloud community.

More than that of the personal experience we rely upon the experts’ evangelicals and views, and the same theme has accounted for Monolithic applications and architectures since after the prevalent of some certain buzzwords like microservices, containers and serverless architecture. Undoubtedly, monolithic applications are notoriously complex to manage and deploy, updating and scaling larger applications sound like a massively troubling task, however, its biggest flaw is the biggest reason to support it. The monolith architecture is simply perfect for small applications because it would be easy to maintain, and its problems would relatively easy and predictable — meaning that the problems arise as our application grows and complexity. For the applications that are either small or demand no frequent changes, or the applications for which we do not know the complete domain and scope, I found monolith pattern even better for the following reasons:

  • Single solution is much easier to build and manage. Also, it gives you fast deployment.
  • Problems can easily be tracked and resolved, moreover, we do not need much skilled and allrounder teams for this legacy monolith pattern.
  • The development is simpler, and integration is just a function-call away.

But when your application goes beyond the normal size, then you need to draw some domains, and sketch the areas where you are going to break the application down to smaller levels. That is when you create the services and develop in a service-oriented pattern. These services in modern day are known as the microservices. The reason I am mentioning microservices, is because serverless and microservices are often confused and used interchangeably.

Serverless approach although focused and resembles the microservices, or service-oriented architecture in the simplicities, deployment and inter-service-communication. But serverless more likely is a practice, like DevOps. In serverless approach, we write our applications targeting the best possible outcome in terms of performance, and lesser overhead and wait-times in the overall execution of our request. As a developer, our role is to write the software that utilizes the cloud platform to its fullest. In the same time, we also target to decrease the overall cost of our solutions.

On the cloud, the cost is charged based on several factors,

  • Compute power used.
  • Memory and storage used.
  • Network traffic being used.

These three main areas of the cloud are the ones that incur charges. Serverless aims to minimize this, and it does so by,

  • Leaving the orchestration part to the cloud provider.
  • Only targeting the main job to be done — underlying runtimes, frameworks are not managed by you!
  • Rearchitecting your monolith, as somewhat like serverless approach.

Serverless approaches on Alibaba Cloud take the same step for our applications. Alibaba Cloud provides us with the Alibaba Function Compute service, that can be extended to support a complete application deployment in miniature microservices, that conform to all the requirements that we have on the cloud environment.

Before we start with the Alibaba Cloud Function Compute, it is better to explain the serverless concept, and how serverless helps organizations do more and pay less on their cloud budget. Also, one thing, this is not an Alibaba Cloud Function Compute starter guide, to learn how to create a function please check out one of our other posts on Alibaba Cloud, in this post we will discuss how Alibaba Cloud Function Compute can be used to migrate your existing monolith APIs to serverless functions.

Slaying the Monolith Architecture

Writing code sophisticatedly had become the norm in almost every software company. However, this isn’t a bad practice but if this sophistication comes along with the fear that what if other things will get affected by making any kind of changes in any specific module, due to coupled and dependent code then this sophistication cannot be taken positively, especially in an ever-growing environment. For monolithic application, even the senior developers do hesitate while making changes without being extremely worried about performance of overall application in the production because they know tweaking in any of the module can be risky and can make them sit for long hours to track what is making your application crashed.

So, we need something less dependent, decoupled and easy to build and develop architecting model, which is the actual topic of this article.

Bringing Cloud in the Scene

Somehow and somewhat, we all have used software engineering design pattern in any of our projects. All these patterns are designed to fulfill a specific kind of problem and requirement. In, the same way we do have various kind of cloud pattern depending upon the user need and usage. From the wide variety of these design patterns the one which has usurped the monolith pattern and resolve the scalability and management issues of such large applications is serverless pattern. And this is the pattern that Alibaba Cloud Function Compute provides us with.

Serverless is not only about the development of the solutions in a distributed and service-oriented fashion, but it also helps us manage, and in most cases even help us decrease the cost of the cloud infrastructure that we have purchased. In the next sections, we will explore how scalability happens on the Alibaba Cloud Function Compute and how we can deploy our solutions online.

How Alibaba Cloud Function Compute helps

Functions are small chunks of code which get executed on the cloud for some specific problem, we do not need to worry about building and deploying entire application and infrastructure to make the changes render. Business productivity, customer support and overall management become a lot easier, moreover we can have the support of multiple languages like NodeJS, Python, Java and PHP, this diversified runtime support provides a flexibility and more control over development strategies and patterns. This enables you to quickly lift-and-shift your existing APIs and deploy them right away to the Alibaba Cloud Function Compute. For example, the following image shows the supported runtimes,

From simple APIs to larger integrated applications such as IoT and microservices based scalable projects, function compute is great way to process data and synthesize information. Function compute provides us various template to get started with our scenarios.

What it Provides?

Management means setup, configurations, infrastructure setting and then issue fixing, when every resource will be busy in this so how business will grow, and team’s productivity will be showcased? So, function compute provides all sort of management and monitoring. It supports the ‘Pay as you go’ billing strategy which is usurping the other models, where you will have to pay only for the seconds and minutes when you’re using the computing resources.

Runtime, SDKs, supported languages

  1. Node.js
  2. Java
  3. Python
  4. PHP

It is up to the taste and personal satisfaction, as to which language of choice one must select. My favorite among these is Node.js, with 8th version of Node.js we get everything for a modern cloud-native application — which can easily help us to build, develop and deploy the solutions, and at the same time manage the cost of our applications too, using async/await keywords.

Function Hooks — HTTP-based and Trigger-based

This gives us the flexibility to either expose our functions to the outside world, or just keep the triggers in the VPC on Alibaba Cloud. In this fashion, if we utilize the HTTP-based triggers, we can rewrite each individual API endpoint as a function. So, imagine in this way that your own APIs are being written as,

  1. GET /person
  2. POST /person
  3. GET /person/all
  4. GET /person/1234

If you already have an API that corresponds to this URL endpoint list, then you can see that these can be quickly upgraded to functions. Now with functions, you get 2 benefits:

  1. You only get to update the function, that needs a change. Rest of the functions can continue to serve your clients, and they do not face any down-time.
  2. Your functions can scale individually, independent of how other functions are performing.

The second point is what gives the actual benefit of using the serverless functions approach with Alibaba Cloud Function Compute. In this approach, your functions are separate tasks and process running and serving the clients. Just because the GET request to /person/all, needed to scale, does not require that you also add more resources for a POST /person, function that is merely getting any request. So, instead of a complete scale of your instances, you only scale a single process and rest of the functions do not get additional resources — unless they need, of course. For example, the following screenshot demonstrates how a single service can be used as a hosting for an API, and each endpoint and HTTP verb can be a functional unit,

This service can contain extra functions such as this image demonstrates,

This way we can create as many extra functions as we need, and they will be independent of each other, in terms of development and deployment.

Alibaba Cloud also offers that you attach these serverless tasks with other resources on the cloud too. Meaning, that instead of having to send an HTTP request to the function, you can attach these hooks to other resources like OSS, RAM, etc. and have the function react to the changes. This is although a less useful way, because you are no longer supplying your APIs, but this is a useful way to utilize a cloud-watcher-like service on the cloud. For example, the trigger selection page lets you specify the sort of trigger you want,

And you can specify the type of trigger you want. Since we wanted to discuss the HTTP triggers, we selected the HTTP one to create the APIs, you can utilize other modes and try them out too.


Follow me to keep abreast with the latest technology news, industry insights, and developer trends.