Serverless architecture and Functions-as-a-Service (FaaS) are hot trends in cloud computing. Besides Microsoft and Amazon, there are many other vendors providing FaaS. This article is a short introduction to serverless architecture where I try to explain what it is and why we need it.
Evolution of the Cloud
During its evolution, the cloud has had multiple forms and abstraction levels.
The data center, be it on-premises or provided by a vendor as a service, was the first step to the cloud as we know it today. It abstracted the physical hosting environment, and we started scaling those environments with hardware units. As virtualization evolved, we started hosting virtual machines on cloud environments. We abstracted the hardware and used operating systems as the unit of scale. Soon after this, we built hosting environments to the cloud and abstracted the operation system. Our new scaling unit was the application. But this was not the end of the journey, as now we've moved to functions or serverless architecture.
Different cloud models leave us different responsibilities. Having the data center on-premises means that we have full responsibility over everything that is going on there. When moving to the cloud, each step in the evolution leaves us fewer and fewer responsibilities.
Serverless architecture actually came later than SaaS, but it is before SaaS in the chart because in the case of SaaS, consumers don’t control anything about the application or its infrastructure.
Functions are the unit of scale in serverless architecture that abstract the language runtime. We don’t talk about how much CPU or RAM or any other resource we need for a function to run. We talk just about the time it takes to run the function. All other metrics should not bother us. We write our functions, publish them to the cloud, and pay only for time these functions ran.
Serverless architecture doesn’t strictly specify what our function technically must be. It is just some unit of work that we want to be done. Functions can be triggered many ways. It can be a timer that runs a function periodically, but it can also be HTTP request or some event in some related service.
In his excellent article Serverless Architectures, Mike Roberts brings out six points about Functions-as-a-Service:
- Fundamentally, FaaS is about running back-end code without managing your own server systems or your own server applications.
- FaaS offerings do not require coding to a specific framework or library. FaaS functions are regular applications when it comes to language and environment.
- Since we have no server applications to run, deployment is very different from traditional systems – we upload the code to the FaaS provider, and it does everything else.
- Horizontal scaling is completely automatic, elastic, and managed by the provider.
- Functions in FaaS are triggered by event types defined by the provider.
- Most providers also allow functions to be triggered as a response to inbound HTTP requests, typically in some kind of API gateway.
If your PaaS can efficiently start instances in 20ms that run for half a second, then call it serverless.
From this, we can conclude that long-running workflows and other massive tasks are not a good fit for serverless architecture.
There are already companies that run functions as a service. Here are some of these:
- Microsoft – Azure Functions
- Amazon – AWS Lambda
- Auth0 – webtask
- Iron.io – IronWorker
- Planet Rational – webscript
There are many other services available, and all of these differ by their technical capabilities and implementations.
Serverless architecture allows us to build pieces of code that do something useful, and at the same time, run quickly without consuming big amounts of server resources. It doesn’t mean that FaaS is usable only in small scenarios. Although a function is a small unit, it can be invoked millions of times per second, for example. The question is what small functionalities we should move from other components or layers of our application to functions.