Serverless - an overview starter guide
Serverless is not new. Up until the mid-2000s, servers were giant rooms that lived on-premise to provide businesses with the infrastructure they needed to run their centralized software systems. Then along came cloud computing, along with ideas like elastic load balancing, on-demand self-service, resource pooling, and infrastructure as a service.
Cloud computing turned infrastructure into convenience and made it highly accessible, especially for the 'little guys' that did not have big infrastructure budgets to buy the hardware to run their services.
By the time 2015 rolled around, the term 'serverless' was thrown around. The idea behind serverless is that the provider took away the need for teams to manage server configurations and architectures. This meant that developers can focus on the business logic and nothing much else.
From here, Function as a service (FaaS) came into existence.
What is FaaS?
The idea behind FaaS - or Function as a Service - is a cloud computing service that lets developers develop microservice-based applications without the need to worry about infrastructure-related activities such as provisioning, load balancing, and architecture.
With FaaS, all the hardware, operating systems, virtual machines, and general management are left to the FaaS provider. The benefits of FaaS are:
- more code, less infrastructure: your servers are scaled automatically and independently by your chosen provider. This makes it cost-effective in terms of time and resources as it doesn't require a developer to set up everything.
- automated scaling: there is no need to worry about provisioning for peak times, capacity planning or when no one is using your functions. You only get charged for what you use. This is scaled in an automated manner and is event-based.
- high availability: FaaS tend to have multiple availability zones, making it a distributed system that can run in different regions without incurring extra costs.
What is Serverless?
FaaS is a subset of Serverless. While FaaS is targeted directly at functions that can be used to orchestrate different parts of the business logic, Serverless deals with anything where the responsibility of infrastructure provisioning and architecture can be delegated to the provider.
This means that serverless also includes services such as compute, storage, databases, and API gateways. The processes of serverless are generally invisible to the end-user and wholly managed by the provider.
How to structure a Serverless FaaS project
When it comes to creating a FaaS serverless project, there are two types of functions - RESTful
and Reactive
.
RESTful
functions are your traditional RESTful
functions. It runs when an HTTP
request is made. A reactive
function gets executed in a FaaS when something changes.
The general structure for FaaS is that there is one file per function. The function also belongs into a RESTful or reactive folder. You then split the backend into resource groups to keep everything tidy and traceable. Here is an example of a file structure based on eCommerce resource groups.
functions
- orders
- reactive
- restful
- payments
- reactive
- restful
- users
- reactive
- restful
With this file structure, you can build out your entire backend as functions that either respond to HTTP requests or 'react' to something that happened as a result of a database change or event.
Top serverless frameworks to check out
It's easy to write serverless functions. However, things can quickly get out of hand as your backend requirements grow. This is where frameworks come in. The purpose of a framework is to provide structure and predictability for a project. Here are 7 serverless frameworks to check out for your FaaS project.
Serverless
Serverless is one of the original serverless framework supporters that is free, completely open-source, and written using Node.js. It was developed to help build applications on AWS Lambda and also has support for Azure Functions, IBM Cloud Functions, and Google Cloud Functions.
Zappa
Zappa is a serverless framework for Python. Zappa makes it easy to build and deploy server-less and event-driven applications in the cloud. It works directly with AWS and API Gateway to give each request its own virtual HTTP 'server' through Lambda functions.
Chalice
Chalice is another AWS Python-based serverless microframework. It comes with a command-line tool for creating, deploying and managing your app's functions. You can also create decorator-based APIs for integrating with AWS API Gateway, S3, SNS, SQS, and automatic IAM policies for increased security.
Architect
Architect is a Node.js based serverless framework that helps developers create opinionated database-backed web apps with AWS. The idea behind Architect is to equip developers with tools such as fast local development, smart configurable defaults, and infrastructure as code.
Claudia.js
Claudia.js is a framework that jets you deploy node.js projects quickly and easily to AWS Lambda and API gateways. It comes with built-it deployments, configuration tasks, and sets up a majority of what you need out of the box. You can deploy and update using a single command, manage multiple versions easily, and has a low learning curve to get started.
Webiny
Webiny is a serverless framework built for creating GraphQL APIs, full-stack applications, and websites to run on AWS Lambda and DynamoDB. Webiny is completely open-source that also supports multi-tenant SaaS applications with modern dev toolchain support such as TypeScript, Jest, ESLint, Yarn 2, and Pulumi. You can also use the provided templates to scaffold REST or GraphQL apis.
Up
Up is another free open-source serverless project that lets you create serverless orchestrations with single command deploys. It also comes with structured logging, free SSL and custom domains via AWS ACM. Deployments made with Up is also immutable, meaning that you can roll back to previous versions in an instant.
Wrapping up
While there may be a bit of vendor lock-in for serverless, the code created in a FaaS context is generally independent of where it gets deployed to. For trigger-based FaaS, the code for these events may be tied to your vendor and the triggered service provided. There may also be some initial configurations involved for security policies and accessibility.
Overall, serverless is a cost-effective infrastructure solution that removes the need for infrastructure management. This is all done for you - off-premise and on demand with multiple availability zones across the globe.