Serverless architecture

Serverless refers to the server-side logic implemented by the developer running in a stateless computing container, which is triggered by events and managed entirely by third parties, and whose business-level state is recorded by the database and storage resources used by the developer.

The figure below is from the Official website of Google Cloud Platform. It is a good layer summary of cloud computing. Serverless is a layer built on top of virtual machines and containers, which is more closely related to the application itself.

Advantages of the Serverless architecture

Most companies today need to know in advance how many servers, storage capacity, and database capabilities are required when developing applications and deploying them on servers, whether in a public cloud or a private data center. And you need to deploy running applications and dependent software onto the infrastructure. Assuming we don’t want to sweat the details, is there a simple architectural model that will satisfy this idea? The answer already exists, and it is a new but hot topic in today’s software architecture world — Serverless architecture.

– AWS FeiLiangHong

  • Reduce operating costs:

Serverless is a very simple outsourcing solution. It lets you delegate management of servers, databases, applications, and even logic to a service provider that you would otherwise have to maintain yourself. Since the number of users of this service will be so large, economies of scale will occur. There are two aspects to cost reduction, namely the cost of infrastructure and the cost of personnel (operation/development).

  • Reduce development costs:

IaaS and PaaS exist on the premise that server and operating system management can be commoditized. The result of Serverless as another service is that the entire application component is commoditized.

  • Expansion capability:

One obvious advantage of the Serverless architecture is that “horizontal scaling is fully automated, flexible, and managed by the service provider.” The biggest benefit from basic infrastructure is that you only pay for the computing power you need.

  • Simpler administration:

The Serverless architecture is significantly simpler than the other architectures. Fewer components means less overhead for your administration.

  • “Green” calculations:

According to Forbes magazine, typical servers in commercial and enterprise data centers provide only 5 to 15 percent of average maximum processing power output. This is undoubtedly a huge waste of resources. With the advent of the Serverless architecture, let service providers provide our computing power to maximize our real-time needs. This will allow us to use computing resources more efficiently.

Serverless architecture on Kubernetes

There are a number of excellent kubernetes-based Serverless Architecture (FaaS) open source projects as follows:

  • Faas – 🐳 Functions provides as a Service – a serverless framework for Docker & Kubernetes blog. Alexellis. IO/introducing…
  • Faas-netes – Enable Kubernetes as a backend for Functions as a Service (OpenFaaS) github.com/alexellis/f…
  • fn – The container native, cloud agnostic serverless platform. fnproject.io
  • funktion – a CLI tool for working with funktion funktion.fabric8.io/
  • Fx – Poor man’s Serverless Framework based on Docker, Function as a Service with painless.
  • IronFunctions – IronFunctions – the serverless microservices platform. iron.io
  • kubeless – Kubernetes Native Serverless Framework kubeless.io
  • OpenWhisk – Apache OpenWhisk (Incubating) is a serverless, open source cloud platform that executes functions in response to events at any scale.

The above project is included in Awsome-Cloud-native

FaaS

Function-as-a-service Panorama (image from github.com/amyers1793/…)

Understand Serverless

No silver bullet. – The Mythical Man-Month

Many years ago, we developed software in the form of C/S (client/server) and MVC (model-attempt controller). Then came SOA, and in recent years, microservice architecture emerged. Cloud Native applications have been updated a little bit. To the more fine-grained microservization, the application development is to cope with the unique characteristics of high concurrency and continuous Internet, which requires high performance and scalability. People pursue software development tirelessly, hoping to achieve a balance between the complexity and efficiency of software development. But unfortunately, NO SILVER BULLET! Mythical Man-month Fred Brooks wrote about this decades ago (1975) in The Mythical Man-month. So could Serverlss be the silver bullet?

Cloud changed our understanding of the operating system, a system of original computing resources, storage, and network configuration can be isolated from, but also the elastic extension, but for a long time, when we are in the development and application has not get rid of the bondage of the server (or cognitive), the application must run in both physical and virtual servers, You have to deploy, configure, initialize, monitor and manage your servers and applications, and keep your data secure. Can these clouds simplify things? Let’s just focus on the logic of our code and let the cloud do the rest for me.

Introduce Serverless

The Serverless architecture is a natural extension of the cloud, and to understand Serverless it is necessary to review the evolution of cloud computing.

IaaS

In 2006, AWS introduced the Elastic Compute Cloud (EC2), which is the first generation of Infrastructure as a Service (IaaS). Users can quickly apply for computing resources and deploy their Own Internet services on AWS. IaaS is essentially server leasing and infrastructure outsourcing. Like the water and electricity we use, we don’t import tap water and generate electricity ourselves, but buy it directly from the water and grid companies and pay for what we use.

The real change to IT in EC2 is hardware virtualization (more fine-grained virtualization), and EC2 brings the following five benefits to users:

  • Reduce labor costs: reduce the cost of hiring IT personnel
  • Reduce risk: no longer like their own operation and maintenance of physical machines, worry about all kinds of unexpected risks, EC2 host damage, and apply for a good.
  • Reduce infrastructure costs: EC2 can be rented on an hourly, weekly, monthly, or yearly basis.
  • Scalability: Don’t anticipate infrastructure purchases too early, as they can be acquired quickly through cloud vendors.
  • Time saving: Fast access to resources to conduct business experiments.

That said, there are benefits to IaaS or infrastructure outsourcing, but there are also disadvantages, which we’ll discuss later.

The above are public cloud IaaS represented by AWS, and private clouds built using OpenStack can also provide IaaS capabilities.

PaaS

Platform as a Service (PaaS) is a Platform Service based on IaaS that provides functions such as operating system installation, monitoring, and Service discovery. Users only need to deploy their own applications. Heroku is the earliest generation. Heroko is a commercial PaaS, and there is an open source PaaS, Cloud Foundry, on which users can build private PaaS. If you use both public and private clouds, if you can build a unified PaaS between the two, it’s a “hybrid Cloud.”

The most widely used technology on PaaS is Docker, because using containers can clearly describe the application and ensure environment consistency. Container as a Service (CaaS) is used to manage containers on the cloud, for example, Google Container Engine (GCE). You can also build your own CaaS based on open source software such as Kubernetes and Mesos, either directly in IaaS or based on PaaS.

PaaS is a higher level of abstraction for software that has access to the running environment of the application itself and can be customized by the developer without having to deal with the underlying operating system.

The definition of a Serverless

Serverless is not as easy to understand as IaaS and PaaS because it usually consists of two domains: BaaS (Backend as a Service) and FaaS (Function as a Service).

BaaS

Backend as a Service BaaS (Backend as a Service) is a Service that invokes the Backend one API after another or program logic that has been implemented by others. For example, the authentication Service Auth0 is used to manage data. There are also many commercial services of open source software commonly used in public clouds. For example, Amazon’s RDS can replace our own MySQL deployment, as well as various other database and storage services.

FaaS

Functions as a Service (FaaS) are services. FaaS is a form of serverless computing. Currently, AWS Lambada is the most widely used.

Now when people talk about Serverless, the first thing that comes to mind is FaaS, which is getting a bit loud. FaaS is essentially an event-driven, message-triggered service. FaaS vendors typically integrate a variety of synchronous and asynchronous event sources and subscribe to these event sources to trigger functions on a sudden or regular basis.

The traditional server-side software is different from the application program deployed to the virtual machine or container that has the operating system. Generally, it needs to stay in the operating system for a long time to run, while FaaS is to directly deploy the program on the platform. When an event comes, the program can be triggered to execute, and after execution, it can be uninstalled.

conclusion

BaaS is still service outsourcing, while FaaS enables us to pay more attention to the logic of the application. Both of them make us not need to pay attention to the server where the application resides, but the server still exists objectively.

When we are moving the application to the container and the virtual machine, actually for the architecture of the application itself does not change much, just some of the processes and rules to follow, 12 factors such as the application code, but serverlss for application architecture is an overturned, usually we need to consider the event-driven model, More refined forms of immaturity, and the need to maintain state outside of FaaS components.

Serverless application

Let’s take a game application as an example to illustrate what a Serverless application is.

A mobile game has at least one of the following features:

  • Mobile friendly user experience
  • User management and permission authentication
  • Level, upgrade and other game logic, game ranking, player level, mission and other information

A traditional application architecture might look like this:

  • One app front end, iOS and android
  • Java backend, using JBoss or Tomcat as the server to run
  • Use relational databases to store user data, such as MySQL

Such an architecture allows the front end to be lightweight and do little application logic, just rendering the user interface and sending requests over HTTP to the back end, while all the data manipulation is done by Java programs on the back end.

This architecture is easy to develop, but very complex to maintain, front-end development, back-end development need very professional personnel, environment configuration, but also someone specialized maintenance database, application update and upgrade.

In the Serverless architecture, we no longer need to store any session state in server-side code, but store them directly in NoSQL, which makes the application stateless and helps to scale flexibly. The front-end can directly leverage BaaS while reducing the coding requirements of the back-end, which essentially reduces the human cost of application development, reduces the risk of maintaining your own infrastructure, and makes it easier to scale and iterate quickly by leveraging the cloud’s capabilities.

The advantage of the Serverless

In the previous section, we mentioned five benefits of IaaS. FaaS certainly includes these benefits, but the biggest benefit is how fast and how cheap it is. Reduce the wait time from concept prototype to implementation and cost less than maintaining the service yourself.

Reduce labor costs

Instead of maintaining your own server and worrying about its various performance metrics and resource utilization, you care about the state and logic of the application itself. And the Serverless application itself is easy to deploy by simply uploading basic code, such as zip files of Javascript or Python source code, and pure JAR files for JVMS based languages. No need to use Puppet, Chef, Ansible, or Docker for configuration management, reducing o&M costs. At the same time, it is more intuitive and effective for operations to monitor the application itself instead of monitoring the lower-level and long-term metrics such as disk usage and CPU usage.

As long as there are applications, there will be Ops. However, the role of personnel will change. Deployment will become more automated, monitoring will become more application-oriented, and the lower-level operation and maintenance will still require professional personnel.

To reduce risk

For a system with more and more complex components, the risk of failure increases. We use BaaS or FaaS to outsource these failures to professionals, sometimes more reliably than we can fix them ourselves, using expertise to reduce the risk of downtime, shorten the time to fix failures, and make our systems more stable.

Reduce resource overhead

When applying for host resources, we usually evaluate the maximum cost of a peak to apply for resources, which often leads to excessive configuration, which means that the cost of peak capacity is always paid even when the host is idle. For some applications this is a last resort, such as databases that are hard to scale, and for common applications it may not make much sense, although we all agree that it is better to waste resources than to have the application die when the peak comes.

The best way to solve this problem is not to plan how many resources you need to use, but to request resources based on actual needs, provided that the entire resource pool is sufficient (public clouds are obviously more suitable). Payment is made according to the usage time and the computing resources applied for each time. The granularity of charging is smaller, which helps to reduce the resource cost. This is an optimization of the application itself, such as making each request take less time and consume fewer resources per request, which can result in significant cost savings.

Increased flexibility in scaling

In the case of AWS Lamba, when the platform receives the first event that triggers a function, it launches a container to run your code. If a new event is received at this point, and the first container is still processing the previous event, the platform launches a second code instance to handle the second event. This automatic, zero-management level scaling of AWS Lambad will last until there are enough code instances to handle all the workloads.

However, AWS will still only charge you for the execution time of your code, no matter how many container instances it needs to start to meet your load requests. For example, assuming that the total execution time of all events is the same, calling a Lambda 100 times sequentially in one container costs the same as calling a Lambda 100 times simultaneously in 100 different containers. Of course, AWS Lambada does not have an unlimited number of instances. What if someone launches a DDos attack on you? AWS has a default limit, the default maximum number of concurrent Lambada functions is 1000.

Shorten the innovation cycle

Small teams of developers are developing applications from scratch and deploying them to production in a matter of days. Use short and simple functions and events to glue together powerful apis that drive data stores and services. The finished application is highly available and extensible, with high utilization, low cost, and fast deployment.

Container technology represented by Docker only shortenthe iteration cycle of applications, while Serverless technology directly shortenthe innovation cycle, from concept to minimum feasible deployment time, allowing junior developers to complete projects in a very short time that previously would have required experienced engineers to complete.

Serverless disadvantage

We know that there is no perfect technology, after so many advantages of Serverless, let’s discuss the following disadvantages of Serverless, or limitations and application scenarios.

State management

Stateless is necessary for free scaling, and with stateful services, serverless loses flexibility, which inevitably adds latency and complexity when stateful services need to interact with storage.

delay

Access latency for different components in an application is a big problem and can be optimized by using proprietary network protocols, RPC calls, data formats, or by placing instances in the same rack or host instance to reduce latency.

Serverless applications are highly distributed and low-coupled, which means that latency will always be an issue, making it impractical to simply use serverless applications.

Local test

Local testing difficulties for Serverless applications are a thorny issue. Although you can in a test environment using a variety of databases and message queue to simulate the production environment, but the integration of service application in or end-to-end testing especially difficult, it is difficult to the kinds of connections in local simulation application, and combined with the characteristics of performance and scaling test, and is also distributed serverless application itself, Simply gluing together countless FaaS and BaaS components can be challenging.

conclusion

Karl Marx said of good, productivity decides production relations, the concept of cloud computing emerge in endlessly, its essence is to the configuration and optimization of the production relations and productive forces, the producers to put aside scenario means that the pursuit of technology in tall will such as “cannon dozen mosquito”, make a mountain out of a molehill, encourage everyone to satisfy the curiosity of people, After all, so many scientific discoveries and important inventions are due to toss out, do not want a faster horse, but the invention of the car ford, the invention of explosives Nobel, the cultivation of peas Mendel… At the same time, consider industrializing technology (perhaps changing production relationships) to increase productivity.

This article is also archived at Kubernetes -handbook – jimmysong. IO.

reference

  • Serverless Architectures – Martin Fowler
  • Overview of the Serverless architecture
  • Will 2017 be the year Serverless explodes?
  • From IaaS to FaaS — The Past and present of the Serverless architecture
  • Introducing Redpoint ‘s FaaS Landscape
  • What is serverless free ebook- oreilly.com