A Quick Guide to Serverless Computing World
For any who may still be unfamiliar with serverless computing, take a look at this quick guide on all things serverless and how it's used.
Join the DZone community and get the full member experience.Join For Free
Developing "serverless apps" and deploying "serverless architecture" are gaining a lot more traction in the tech industry. The reason behind the hype of serverless computing is simple: it requires no infrastructure management. Hence, enterprises finds this as a modern approach to lessen up the workload.
BBC, Airbnb, Netflix, and Nike are some of the early adopters of this new approach!
But is it right fit for your organization too? This article will help you to make the right decision.
This post majorly focuses on:
What serverless really is
What problems it can overcome from traditional architecture
How it differs from microservices
Why organizations should opt for serverless computing
What things organizations should keep in mind before adopting
When you should adopt it
What is Serverless Computing?
Serverless computing is an approach of the cloud computing model where code execution is managed by the server and developers do not have to worry about maintaining and provisioning the server when deploying code.
The word "serverless" is actually misleading; it doesn’t mean ‘no servers’. Rather, servers are an integral part of the concept. Developers just have to simply upload functions and specify the resources it requires. The cloud server will take all the provisioning and deploy the functions on it.
It provides an opportunity to the developers to reduce the maintenance costs while allowing the developers to focus on business logic, rather than thinking about infrastructure, security, and upgrades.
How It Differs from A Traditional Approach?
Let’s make it simpler! You’ve developed a web app for user registration which accepts data from the user and then it is stored in the backend database.
Considering the traditional way:
You need to dedicate time and separate resources for managing this
Your server must be responsible for storing data in the backend
You need to make sure that server running your web app is functioning properly
Considering the serverless way:
The service provider is responsible for providing optimum service to the operating system to server management
No need to purchase server; no dedicated resources; hence, reduces time-to-market
Freedom to decide how to use their infrastructure efficiently to serve requests from all clients
By reading this, you may think that if microservices have the same features, then how serverless is leveraging?
Serverless vs. Microservices
It may seem that microservices and serverless are somewhat similar – both services break down an application into chunks of pieces, reduces time-to-market, handle changing requirements with fewer efforts, and lower the operational cost in an environment with a larger load.
But, they are different when it comes to deploying and managing the application.
The microservice architecture looks somewhat like this:
Now have a look at the serverless architecture:
Microservices are not stateless since they run in containers while functions are stateless since they are ephemeral. Microservices groups similar functionalities into one service, while serverless computing divides functionalities into chunks of components. All other infrastructure services remain the same.
The core difference is that the functions end up in a host service, meaning that developers are free from maintaining server and deployment process.
The serverless architecture incorporates two different concepts:
FaaS ( Function-as-a-Service)
Function-as-a-Service is a model of cloud computing in which developers write business logic functions and cloud provider executes the functions. Developers can upload chunks of functionality into the cloud which can be executed independently. Everything from execution to scaling is completely automatic, elastic, and managed by the provider.
Key components of FaaS:
Function: Independent unit of the deployment, including taks like file processing and performing a scheduled task
Events: Anything that triggers execution of the function is regarded as an event, like message publishing, file uploading
Resources: Refers to the infrastructure or the components used by the function, eg: Database services, file system services, etc.
From the figure, it seems PaaS and FaaS are same! But, they are different in some aspects
How is FaaS Different From PaaS?
PaaS: Platform-as-a-Service enables developers to deploy the app and the cloud takes care of deploying on the servers. When an application is deployed as PaaS, it is typically running on at least one server at all times.
FaaS: It provides the ability to deploy a single function or part of an application. It will only run when the functions need to be executed. It starts the function within a few milliseconds and then shuts it down.
Both PaaS and FaaS provides the ability to easily deploy an application and scale it without having to provision or configure servers.
Backend-as-a-service enables developers to write and maintain the only frontend of the application and make the use of backend service without building and maintaining them. BaaS vendors provide in-built pre-written software activities such as user authentication, database management, remote updating, cloud storage etc.
As developers don’t have to manage servers or virtual machines to keep their application running, they can build and launch applications more quickly.
Top Market Players of Serverless Computing
Though this technology is its infancy stage, companies like NetFlix, Coca-cola, Codepen, Zalore, and Nordstrom are getting more inclined to use this service.
Top serverless computing providers are:
|Serverless Computing Providers||Services|
|Google Cloud Functions|
Research shows that Amazon AWS is leveraging for public cloud adoption and Microsoft Azure is the second largest cloud platform.
What Are the Advantages of Using Serverless Computing for Your Enterprise?
Provides Fully Managed Service
Though servers are involved, it provides a fully managed service which means setup, planning, and server management is fully handled by the cloud providers. Developers do not have to worry about underlying infrastructure, operating system, middleware, dependencies etc.
Supports Event-Driven Approach
In serverless, functions are triggered by events such as user actions, sensors or messages from other applications and services. Different cloud services that support trigger mechanism can initiate and launch a function. In an event-driven approach, developers can quickly run, test and deploy their code without getting tangled in the workflow.
What differentiates serverless from the traditional model is the way it scales. Serverless applications can quickly, seamlessly, and automatically scale up/down as per the spikes in traffic. The in-built system will automatically handle things such as load-balancing in order to meet massive surges in traffic. In virtual servers, you need to set up logic, and tell it when to spin up and shut down servers and take care of the event handling. The serverless framework can help to avoid such a tedious task.
Only Have to Pay for Execution Time
For an enterprise, serverless computing can be a massive money saver. Your traditional dedicated server might be charging you 24/7 irrespective of whether you use it or not. However, this is not the case with a serverless framework. You don’t have to pay a fixed price for your server. Instead, you only have to pay for what you have used. When a function is not executed, no charge is incurred; thus it eliminates any idle time.
Rapid Development and Deployment
Serverless computing build, test and release cycles in an agile way which increases the productivity of the developers. It helps to run infinite test cases without worrying about the other components or the infrastructure. Serverless services providers are developing standardize environments to encourage enterprise to use serverless architecture.
Within an hour, you can actually have a look at your developed product. Serverless architecture helps to run multiple versions of code to meet tight deadlines.
Key Considerations While Using Serverless Architecture
Third-party vendor locking: Developers have to be dependent on third-party vendors and services which may lead to system downtime, unexpected limits, loss of functionality and much more.
Lack of operational tools: The developers have to be dependent on providers for debugging and monitoring tools. Debugging distributed system is difficult and needs a number of metrics to identify the root cause.
Complexity: It takes time to decide how small the functions should be, how they would be accessed, implemented and tested. It is difficult to manage too many functions and ignoring the small functions may lead to mini-monoliths.
Functions stay for a shorter period: In serverless, functions are deployed in containers. These containers initiate their process when any specific event is triggered and remains active for a certain period of time and shuts-down automatically removing all the resources from the containers. Thus, it is only suitable for the application which has a shorter process involved.
Limited availability to map database indexes: There may arise performance and scalability challenges due to limitations of the number of simultaneous connections that can be opened in a relational database. Moreover, it may be challenging to configure nodes and indexes
Stateless Functions: Resources within a function cannot exit after function stops to exit. For instance: storing the session state in the persistent database if the sessions need to be preserved.
Use Cases of Serverless Computing
File processing is a crucial thing for preparing and analyzing data. Whenever any large applications are developed, there are some asynchronous file like the generation of thumbnails from uploaded images, scanning of log files etc which needs to be processed. Event-based triggers which are integrated into serverless computing are a perfect fit for the processes.
If AWS is used, a Lambda function can be configured to run the event based on S3 create object-event. When your existing application uploads an image to S3, a lambda function can be triggered by this event to create the necessary thumbnails. With this process, the load is reduced, the cost is levied only the actual processing and is automatically and elastically scaled to handle any load.
Image and Video Manipulation
With serverless, it is easy to provide enhanced video and image service for any application. It helps you to modify the size or can even alter video transcoding for the different target device.
For instance: an e-commerce app that enables customers to photographs the front and back of the credit card instead of typing numbers manually.
Serving Static Content
Let’s say if you have a web app for sharing static content. You can leverage serverless and a robust front end to scrape your content directly from blob (the function of Microsoft Azure). By using this, you no longer have to worry about accommodating load, infrastructure provisioning or scaling server instances.
Is this secure?
Yes, as long as you make it secure.
If you are using third-party service, you need to know how you can lock down access to that service. For instance: if you’re using the browser you need to write custom security rules that are executed by the database engine to determine which users can read/write from the database.
When You Should Opt for Serverless?
Developing an application in serverless is super fast and easy, so if you are planning to develop MVP or PoC and you don’t want to spend time in managing infrastructure, serverless can be the best one.
If your app includes long calculations and requires more memory, it is better to opt for other solutions. Serverless locks you to the cloud which means if you want to move to the private server, you will be able to but its’ not considered as an optimal solution.
Still, if you are not sure, check out the following questions to determine if serverless is right fit or not.
Is your app small or can be broken into small blocks?
Is it feasible to use existing development platform and inbuilt tools?
Does the serverless provider support:
Receiving connections from your clients?
Interact with the target data store?
A language I am aware of?
Netflix is one of the world’s largest online streaming service providers delivering almost 7 billion hours of videos to nearly 50 million customers in 60 countries. Hence to cater to that kind of audience, the company needed as highly complex infrastructure that can ease their work. They used AWS Lambda serverless provider for:
Publishers uploaded thousands of files on Netflix on a daily basis and every file needs to be encoded and sorted before they end up being streamed to the user. When files get uploaded to S3, Amazon triggers an event by using AWS Lambda Function. This function splits the video into chunks which get encoded into 60 different parallel streams. Once the later part of the video is processed, they get aggregated and deployed using a series of rules and events.
Backing up files
Thousands of files get modified regularly. AWS Lambda checks if the files are needed to be backed up. They check the validity and integrity of the files and if anything fails they can backtrack from the scratch and restart the process.
Netflix has thousands of processes that stop and start instances all the time. They use Lambda to validate that each instance is constructed and configured with the system rules and regulations. Alerts are also created for shutdown event of an unauthorized access.
Serverless technology is an innovative computing service that supports changing business requirements. However, it is always better to take expert’s advice from the best software development company that holds years of experience in developing software with modern technologies.
Opinions expressed by DZone contributors are their own.
Effortlessly Streamlining Test-Driven Development and CI Testing for Kafka Developers
A Complete Guide to AWS File Handling and How It Is Revolutionizing Cloud Storage
13 Impressive Ways To Improve the Developer’s Experience by Using AI
How To Backup and Restore a PostgreSQL Database