Serverless application with AWS Lambda and Kotlin. Part 1
Part 1 — Intro to Serverless applications and Functions-as-a-Service
This series of articles consists of 4 parts:
- Intro to Serverless applications and Functions-as-a-Service (you are here)
- First blood: Writing functions in Kotlin for Java platform on AWS Lambda
- Warmup optimization: Writing functions in Kotlin for Node.js platform on AWS Lambda
- Using familiar tools: Writing functions in Kotlin for for Java platform using Spring Cloud Functions on AWS Lambda
Many of us remember a revolution took place in mid 2000s. The name for it is “cloud computing”. With cloud computing there is no need for creating/supporting/decommissioning infrastructure. This makes possible to cut cost for infrastructure and drastically reduce time to minimal viable product.
Nevertheless we are still implying an application as a bunch of machines/servers even virtual. We are creating AWS EC2 instances, setting them up and creating a platform for our application. Docker simplified this approach and provided an unified platform. But still we need to configure it (build, deploy, manage) and it requires a lot of efforts.
But we can abstract from machines/servers.
Serverless platform is intended to solve an issue of supporting infrastructure and concentrate efforts on features important for customer.
Important strong side of serverless application is that the payment is based on usage amount, but not time of use (usually). Basically you pay only for what you use.
As a result, serverless application fits well for cases like:
- services with highly variable load — general rule of thumb to provision this kind of services with performant and expensive instances to fulfill the highest possible load, despite the fact that most time instances will be underutilized
- scheduled tasks
- building prototypes
There are two types of Serverless applications:
- Backend-as-a-Service (BaaS) — usually describes third party services with specific functionality, an example is Auth0 service for authentication or Google Firebase for data storage
- Function-as-a-Service (FaaS) — computing platform managed by cloud provider with simple configuration and no state
In this article we will concentrate our attention on FaaS.
In FaaS application system is separated from single application to number of functions interacting with each other. A function is a simple execution component with a single responsibility and with no state. As long as functions are stateless and lightweight it’s easy to create a new function or shutdown if there is no need for it, therefore functions scale very well.
There is a number of FaaS platform providers:
- Cloud Functions from Google
- Azure Functions from Microsoft
- Apache OpenWhisk for building private cloud with FaaS functionality
- solution from IBM based on OpenWhisk
- AWS Lambda
We will build our simple application on Amazon Lambda as the most popular solution.
AWS Lambda provides interface for different platforms:
- Serverless applications do not require instance managing therefore developers can concentrate efforts on features valuable for users.
- Serverless applications scale well.
- Cost are based on usage, but not provided capacity. This make possible to reduce costs for applications with highly variable load.