Provisioning, maintaining, and operating servers and runtimes is a resource-intensive undertaking that keeps organizational teams from focusing solely on business innovation and core functions. Consequently, organizations are shifting towards a serverless cloud computing architecture, which involves transferring the deployment of applications and the server-side of IT to external service providers.
Serverless is the idea that organizations can run server-based applications without having to manage a server. The serverless model requires that applications be deployed as a set of autonomous components that are built “as a service” and can be invoked on-demand, incurring costs only when in use.
Dgtl Infra explains serverless computing, its architecture, and how it differs from other cloud computing models. We also dive into the advantages, disadvantages, and common use cases for serverless. Finally, we highlight the major serverless services from cloud service providers (CSPs) like Amazon Web Services (AWS), Microsoft Azure, and Google Cloud.
What is Serverless?
Traditionally, organizations supported the infrastructure needed for running their applications and workloads on their premises. Technologies like server virtualization allowed them to create several virtual servers, each with its own operating system (OS) and runtime, on a single physical server for better resource utilization. Next, cloud computing models like Infrastructure as a Service (IaaS) and Platform as a Service (PaaS) emerged, allowing organizations to offload their infrastructure needs to a cloud service provider (CSP) for ease of management, greater elasticity, and cost-effectiveness.
However, organizations, particularly developers, are still responsible for some configurations, such as setting up the deployment environment, managing software licenses, and spinning up virtual instances as needed.
Serverless Computing Definition
Serverless computing, or “serverless” for short, hides the entire backend architecture from developers. It abstracts the application as autonomous functions that are hosted, managed, and maintained by a third-party provider. These functions are then consumed as a utility service, executed only when invoked. The costs are also incurred based on the number of times each function runs.
“Serverless” is, in fact, a qualifier that can be applied to any software or service offering, which requires that it is consumed as a utility service and incurs cost only when used. For example, software that requires a server to host a website, such as the Apache HTTP Server, is not serverless since it does not meet the “consumed as a utility service” criterion. Similarly, software that is available “as a service” but requires a fixed base subscription fee regardless of usage, such as Salesforce, is also not serverless since it does not meet the “incurs cost only when used” criterion.
With serverless, developers are solely responsible for creating the business logic of applications, not the underlying software and hardware stack. Serverless applications execute only in response to specified events and traffic – and can automatically scale up and down, even to zero, without prior forecasting or configurations. Serverless architectures promise developers the ability to iterate as fast as possible while maintaining business-critical latency, availability, security, and performance guarantees with minimal effort on the developers’ part.
How Does Serverless Work?
Serverless computing does not mean that servers or operation engineers are no longer required to host and run code. It merely refers to the idea that consumers of serverless computing are no longer responsible for server provisioning, maintenance, updating, scaling, and capacity planning. Instead, all of these tasks and capabilities are abstracted from developers and in-house IT/operations teams and delegated to the serverless platform and service provider. Said differently, the “less” in “serverless” indicates invisibility in the context of usage, not absence.
Serverless applications can be built using a collection of managed services or functions that can be called via application programming interfaces (APIs). This is known as the backend as a service (BaaS) model. For instance, developers may use one service for authentication and another for data storage and retrieval. Alternatively, developers can write custom server-side logic that runs in containers fully managed by a cloud service provider (CSP). This model is known as function as a service (FaaS) and is more commonly referred to when talking about serverless.
In any case, developers are not responsible for configuring or managing infrastructure to run these services. These services do not rely on direct access to a server to work. Instead, the cloud service provider spins up a short-term server whenever the application needs to run. The server is terminated as soon as the tasks are completed. Unless invoked, serverless applications do not reserve or consume any resources, allowing for strictly “pay-per-use” billing.
Serverless architecture is primarily event-driven. It leverages serverless implementations – no manual infrastructure configurations – of individual, autonomous components that are provisioned “as a service”. Services then run and communicate with each other in response to specific event triggers. Developers can use various powerful, single-purpose APIs and web services to build loosely coupled, scalable, and efficient applications quickly.
A serverless architecture for an application can have multiple layers, each using existing services from cloud providers like Amazon Web Services (AWS) and Microsoft Azure to implement its architectural components. Cloud service providers offer entire catalogs of serverless services for creating APIs, workflows, queues, databases, and more.
Serverless Architecture Example
As an example, consider a simple serverless web application for requesting a ride, through an on-demand ridesharing application like Uber, built using AWS serverless services. It may utilize Amazon API Gateway for routing user requests (event triggers) to relevant AWS Lambda functions. The Lambda function executes necessary operations like selecting an available ride from an Amazon DynamoDB table and returning the results to the user.
Essentially, the Lambda function, upon invocation, will run on a stateless container which will be terminated once the function is executed.
Advantages and Disadvantages of Serverless
Serverless is about offloading the undifferentiated heavy lifting to others, reducing certain operational concerns, moving toward event-driven computing, and giving organizations space to focus on what is important – the core goals of their business or project.
What are the Advantages of Serverless?
The advantages of serverless are organizational focus, scalability, high availability, pay-per-use, and reduced complexity.
- Organizational Focus: serverless architecture allows developers to focus on software design and business logic rather than infrastructure, software licenses, and capacity planning. As a result, organizations enjoy accelerated innovation and a faster time-to-market
- Scalability: serverless systems automatically scale up and down within seconds. In fact, they allow granular scaling of particular functions facing high demand. Developers do not have to plan for sudden and unpredictable demand spikes, except when interacting with other non-serverless components or systems
- High Availability: serverless architecture offers high availability as a standard feature. Organizations can deploy their serverless applications across different availability zones in separate geographical cloud regions with no incremental costs. It allows organizations to integrate disaster recovery services and ensure high availability and performance as per the cloud provider’s service level agreement (SLAs)
- Pay-per-Use: serverless is more cost-efficient because consumers pay only for what they use. Serverless applications and systems can rapidly scale down to zero activity, meaning no resources are wasted during idle times. Consumers are charged based on the number of times a function is invoked or a task is performed instead of instance hours
- Reduced Complexity: serverless eliminates undifferentiated code such as that required for orchestrating server fleets or routing requests and events between components, which forms a surprisingly large part of modern code bases. In turn, development teams have less code to write and maintain per application
What are the Disadvantages of Serverless?
The disadvantages of serverless are execution time limits, cold starts, vendor lock-in, and loss of control.
- Execution Time Limits: a key weakness of serverless is the limited amount of time a particular workload can run before being terminated. For example, AWS Lambda functions can only run up to 15 minutes per execution. There are workarounds, but it may be more cost-efficient to run long-running applications on dedicated servers than serverless
- Cold Starts: serverless can scale to zero during idle time, leading to cost cuts. However, if a function is executed after its resources are spun down completely, the execution environment will have to be initiated once again on the next call, which takes time. As a result, serverless offers different performance characteristics for frequently or recently executed functions versus inactive functions. Again, there are workarounds to avoid cold starts, such as keeping resources on standby or initiating dummy requests. However, such workarounds can challenge the “pay-per-use” characteristic of serverless
- Vendor Lock-In: another downside of serverless computing is that the function code is directly tied to the software platform it runs on. Over time, this could limit portability as the application architecture becomes strongly coupled to the platform being used. Applications and workloads that need to remain vendor-agnostic must be architected keeping in mind the implications of vendor lock-in and the inherent risks of third-party services, such as data sovereignty, services portfolio, cost, and support
- Loss of Control: efficiencies gained by offloading the ‘heavy lifting’ to CSPs come at the expense of visibility and control. Developers lose the ability to customize the operating system (OS) or tweak the underlying instance. Additionally, when all of the compute is ephemeral, diagnosing issues and debugging the code become exceptionally complex. Different service providers offer varying levels of customization and flexibility
When Should Serverless be Used?
Based on the characteristics and advantages of the serverless approach, it is best suited for unpredictable traffic loads and organizations that need to innovate and move quickly. Serverless functions are versatile in that they can be used to build backends for CRUD (Create, Read, Update, Delete) applications, e-commerce, back-office systems, complex web applications, and all kinds of mobile and desktop software. Serverless functions are stateless by default, which makes them perfect for implementing any logic that benefits from parallel processing.
When Should Serverless Not be Used?
To adopt serverless, it is necessary to break the application into smaller workloads. Considering the drawbacks and concerns surrounding serverless, it does not work best for tasks that are computationally intensive or have a long runtime, which cannot be broken down into multiple compute cycles.
Serverless Use Cases
Serverless technologies and architectures can be used to build entire systems, create isolated components, or implement specific granular tasks. The scope for the use of serverless design is broad – it can be used to architect systems that power web and mobile applications for tens of thousands of users, as well as to build systems that solve very specific, minute problems. In fact, it is often used for backend tasks that power complex websites or applications.
Examples of Serverless Use Cases
Examples of serverless use cases include backend compute, real-time analytics, the Internet of Things (IoT), and periodic cloud tasks.
1) Backend Compute
The near-infinite scale and event-driven architecture of serverless, allows precise compute power for any scale, making it suitable for backend tasks like data processing in bulk. With serverless, organizations can break up and parallelize work – and instantly feed it to as many serverless functions as needed. For instance, the time it takes to process one minute of high-resolution video for streaming is also the time it takes to process a 90-minute film, as the film can be broken down into smaller snippets and processed simultaneously. This is one example of how Netflix uses serverless.
2) Real-Time Analytics
Serverless functions are suitable for applications that generate a lot of data that needs to be analyzed, aggregated, and stored. Fully managed serverless functions can scale automatically depending on the volume of data coming in.
3) Internet of Things (IoT)
Serverless is an excellent fit for the Internet of Things (IoT) applications that use the internet to read and write data. A serverless application backend removes a lot of infrastructure management, offers granular and predictable billing, and scales well to meet uneven demands. That is why services like Alexa, Amazon’s virtual assistant technology, and iRobot, which designs and builds consumer robots such as vacuum cleaners, utilize serverless.
READ MORE: Internet of Things (IoT) Devices – What’s Smart in 2023?
4) Periodic Cloud Tasks
Serverless functions can be used to automate cloud tasks that do not need a server running constantly but must be performed on a recurring basis, such as performing periodic database backups and automated software updates.
There are numerous serverless services and platforms that organizations can choose for going serverless. Since there are quite a few approaches to implementing serverless, all providers have distinct services. Organizations should consider the entire portfolio of services a provider offers and its service level agreement (SLAs) to ensure they can successfully adopt and benefit from serverless architecture.
Below are some of the serverless services from major cloud service providers (CSPs):
Amazon Web Services (AWS)
Amazon Web Services (AWS) offers a comprehensive portfolio of services to enable and support serverless architectures. They include:
- AWS Lambda: a serverless compute service for running code
- Amazon S3 (Simple Storage Service): a serverless, fully elastic, and highly available object storage service
- Amazon DynamoDB: a fully managed, serverless NoSQL database service
- Amazon Aurora Serverless: on-demand, autoscaling configuration for Amazon Aurora – Amazon’s MySQL and PostgreSQL-compatible relational database service
Microsoft Azure’s serverless services include:
- Azure Functions: a serverless compute platform for running code
- Azure Cosmos DB: a fully managed NoSQL and relational database service with a serverless offering
- Azure Bot Service: an intelligent, serverless bot service
- Azure Event Hubs: a fully managed, highly scalable data and event ingestion service
Google Cloud’s serverless services include:
- Google Cloud Functions: serverless compute for running code
- Google App Engine: a serverless platform for hosting web and mobile applications
- Dataflow: a fully managed, serverless service for stream and batch data processing