In recent years, serverless adoption has started, with more and more individuals depending on serverless technology to meet organizations’ specific needs. A survey conducted by Serverless Inc showed in 2018 that half of the respondents used serverless in their job, and the numbers are projected to rise further.
In this post, we would get around the terms so that you can start your own serverless journey 😉
Let’s get started!
What is a Server?
If you have been on the internet even for a while, you have undoubtedly interacted with a server. Servers are a piece of specific hardware which ‘serves’ information or data to you. The specific hardware contains a lot of memory, speedy internet and generally hosted in massive data centres with other servers.
Hosting websites by buying your server is something you can think of, but you get limited if the numbers you calculate are wrong, which generally is the case. The under-provisioning (having less server capacity than required) and over-provisioning (having less traffic than the server can handle) of servers would take time from your development and cost you money.
You can always jump into a scalable cloud computing infrastructure. Still, then there, you must manage your infrastructure and would have to set aside time for your infrastructure management from the total time you could focus on development. Serverless helps you with this aspect.
Companies often invest less in cloud computing by using serverless services. The organization only pays the cloud service provider for the time their code is executed, instead of paying a flat fee for virtual machine (VM) instances that are always under- or over-utilized. Time is calculated in the form of applications, sometimes billed for every million requests. AWS, for example, charges about $0.20 for its serverless product per million requests.
What is Serverless?
Serverless helps you run an application without the need to configure or own the infrastructure even when the demand increases on an as-needed basis.
There’s a misconception that serverless doesn’t require a server, but that’s completely wrong. Serverless run on the server, but the term signifies that you don’t need to worry about servers and the cloud provider takes care of them. They are the most flexible and cost-effective cloud computing technique to date.
How Serverless Works?
Developers rely on serverless to execute specific functions within the application code. We can call this model as a Functions as a service (FaaS) model due to this function-based approach.
If broken down into steps, a serverless lifecycle looks like this:
- Code Generation: Developers create a specific use case function with their choice of language.
- Event Declaration: A function only starts to pop up when an event happens. The event is often an HTTP request but can be queues, timers, and other various ways to trigger the function.
- Event Triggers: As soon the event is triggered via the specified ways, the function is executed. The trigger can be an application requesting information or a user clicking a button generating an HTTP response, or hundreds of other triggers.
- Function Execution: Before the function starts running, the cloud provider checks if an instance of the function is running or not. If not, it forms a new one for the function.
- Output: The function on execution generates a result that is sent back to the application specified on the code generation phase.
Why use Serverless?
No Servers to Manage
You don’t have to worry about calculating how much hardware you need to provision for your requirements with FaaS. You can go to the market fast with your product because now you’re focusing mostly on your development and don’t have to worry about installing dependencies and other libraries.
FaaS helps you to scale automatically up and down if your service traffic fluctuates. Forget about configuring scale sets to scale your VMs, i.e., servers, if a sudden influx of traffic occurs. Your service on FaaS will scale automatically if it’s day or night, just depending on how much traffic you get.
Pay for usage
With traditional VMs, you can fall into the trap of the wrong size configuration of VMs (leaving full capacity unutilized), which could cost you extra money. Moreover, if you forget to shutdown VMs which are not in service, you could reck up a hefty bill.
FaaS charges you for the requests or the function trigger and not any other parameters. This request billing translates into you only have to pay for how many requests you are getting and nothing extra.
Why are the drawbacks of using Serverless?
The Serverless Computing environment dictates that functions are run on demand and, when not needed, are thrown away. All these efficiencies lead to a phenomenon called cold starts.
A cold start happens when your function is running the first time in a while. The underlying reason for this is the function must be downloaded, containerized, booted and primed to be run. This problem could increase your service latency if traffic spikes, and so some providers try to minimize it by pushing function on edge.
For visualization, think in a cold-weather your engine takes more time to start than when the engine was working a few minutes ago.
Third-Party Vendor Lock
Each cloud provider deals with its infrastructure differently, but migration is easy because it’s similar on an infrastructure level.
Serverless removes the complete responsibility from your shoulders and put them on the cloud providers. It merely means they are managing infrastructure, and now if you want to develop an application, you have to follow the providers’ path, which is different for each provider.
Suppose a serverless application is developed on a specific provider. In that case, it becomes hard to migrate to another provider (in case you’re getting a better deal there) as a different management system exists. This difference in management system helps the provider lock-in clients. You can see that’s why some cloud providers offer free tier encouraging developers to develop an application on top of their serverless infrastructure.
A typical application requires networking, disk, memory and API requests to function. Cloud providers try to outsmart customers by charging a different amount for each service or component need for an application to work. These costs add up drastically, and in some scenario owning your server via a cloud provider comes cheap.
The cold starts also come costly as the users have attention spans in milliseconds, and if it takes more time than that, users will return to some other website. Fun Fact: Only AWS as few milliseconds cold start timing azure and GCP have them measured in seconds (more than 2 seconds in most case).
Read more about hidden costs in this awesome blog.
Serverless is a new technology that is under development and makes your developer life easy. A long way to go yet in terms of technology to mature!
One thing to remember serverless can’t be a perfect use case for all your development life cycle, but if sifted through, some cool stuff can be build using serverless.