Breaking Down Serverless: The New Cloud Norm

Nadar Alpenidze
9 min readJul 29, 2024

--

Digital clouds hovering above servers (Midjourney)

Introduction

Imagine you’re building a startup with a limited budget, minimal engineering resources, and very tight deadlines. Critical decisions arise, such as determining the number of servers needed to support your expected customer base. What about handling unexpected traffic spikes? And what about the precious resources wasted if your estimates are off? Surprisingly, with serverless architecture, these concerns become a thing of the past.

Serverless architecture radically changes the game by eliminating the need for traditional server management. In a serverless world, the infrastructure effectively becomes “invisible” to developers—we neither know nor need to concern ourselves with the number of compute nodes running our applications. Instead, we hand off the complicated management of servers to cloud providers like AWS.

In this article, we’ll explore the nuances of “serverless” architecture and uncover why it has become a buzzword in the world of cloud computing. Nearly every major cloud provider today, including AWS with Lambda, Microsoft with Azure Functions, and Google Cloud with Google Cloud Functions, offers serverless options. Let’s dive deep to understand this transformative technology and its impact.

What Is Serverless

Serverless is a transformative model in cloud computing that revolutionizes how developers build and execute applications. In this model, the heavy lifting of provisioning and managing servers is delegated to the cloud provider, freeing developers from the intricacies of server management.

While serverless might imply an absence of servers, that’s not quite the case. Our applications, like any others, require computing resources such as CPU and RAM to function. The essence of serverless lies in its ability to abstract the operational responsibilities away from developers, allowing them to concentrate on business-critical tasks such as writing code. This means no more managing servers or worrying about the operational aspects of application deployment.

In serverless architecture, computation occurs in stateless containers that are event-triggered and ephemeral. These containers, which are managed by the cloud provider, are instantiated based on demand to handle incoming requests to our applications.

A key aspect of serverless architecture is the concept of ‘Functions as a Service’ (FaaS). We deploy our code to ‘functions’ hosted by the cloud service. These functions then execute our application in response to incoming events, such as an HTTP request. A prime example of FaaS is AWS Lambda. This perspective simplifies the application development process and allows us to focus exclusively on evolving our application logic and business instead of worrying about the infrastructure.

However, serverless computing encompasses more than just FaaS. It refers to any cloud service model that automatically and elastically scales to handle various workloads. Consider the example of traditional databases versus serverless databases: In a traditional MySQL setup, a sudden tenfold increase in workload could bottleneck your database. On the other hand, a serverless SQL model like AWS Aurora automatically scales to meet the increased demand. Similarly, AWS SQS offers a serverless alternative to message queuing, unlike Apache Kafka, which requires manual cluster configuration and scaling efforts.

Figure 1. Traditional vs serverless infrastructure

Serverless also introduces the concept of ‘Backend as a Service’ (BaaS). BaaS automates and abstracts the backend development process, offering services through APIs and SDKs directly to front-end applications. Services like Auth0 for authentication and Firebase for databases exemplify serverless BaaS, streamlining both front-end and mobile development. While BaaS is an integral part of serverless, this article will primarily focus on serverless in the context of FaaS.

Benefits of Serverless Architecture

Serverless computing offers many benefits, making it an appealing choice for teams and companies. Let’s explore these advantages to understand the range of problems serverless can solve.

Scalability

Scalability is a fundamental aspect of serverless architecture. Traditionally, developers and operators had to estimate the number of servers needed for their applications and acquire this capacity in advance, whether through cloud services like EC2 or by purchasing bare metal servers. This approach, however, possesses challenges, especially when it comes to scalability.

Consider the scenario of an e-commerce application that experiences intermittent traffic spikes, potentially up to 5X the normal load. In a traditional setup, this would mean provisioning infrastructure capable of handling these peaks. This results in over-provisioning your infrastructure to handle traffic spikes, which most of the time is excessive and lies underutilized, leading to a significant wasted expense. To put it in other words, you are running 5X the infrastructure required for your normal traffic, resulting in almost 5X more cost.

With serverless, you run only the amount of hardware that is required to serve your traffic. As demand increases, the cloud provider automatically allocates more resources. Conversely, when demand drops, it scales down, ensuring you’re not paying for unused capacity.

Figure 2. Inefficient over-provisioning of traditional architecture

Cost Efficiency

Serverless operates on a pay-as-you-go model. You’re billed only for the compute resources and execution time your functions use. In contrast, with EC2 instances, billing occurs per hour regardless of whether the server is fully utilized.

This directly relates to scalability. For instance, if your e-commerce application experiences a slow sales day, your costs will be significantly lower than maintaining a fully provisioned infrastructure designed to handle peak traffic, including unforeseen spikes.

Reduced Operational Costs

Serverless greatly reduces the need for human labor in operations. Traditional virtualized environments like EC2 require ongoing infrastructure maintenance, including hardware updates, patching, and security management. Serverless architectures offload these tasks to the cloud provider, freeing you from these concerns.

Faster Time-To-Market

An often-overlooked yet crucial aspect of serverless is its impact on speed and time-to-market.

Serverless architecture enhances agility, allowing for rapid product improvements. It shifts focus away from operational concerns, letting you concentrate solely on coding. The deployment process is streamlined: code is written, pushed to the FaaS service, and immediately ready for customers.

In my previous article about microservices, I emphasized the importance of CI-CD pipelines for rapid iteration. Implementing CI-CD pipelines in serverless environments is equally crucial to streamline your service’s release process and ensure robust testing and approval workflows.

FaaS v.s. PaaS v.s. Containers

When learning about serverless, we may get confused by similar cloud solutions such as PaaS (Platform as a Service) and containers. Initially, they look pretty similar, but they provide developers with different levels of abstraction, control, and scaling mechanisms.

FaaS stands out for its high level of abstraction. Here, developers focus solely on writing code while the cloud provider handles scaling, maintenance, and runtime. Functions in FaaS are stateless; their runtime environments are ephemeral and can be terminated at any time.

PaaS, a layer above IaaS like EC2, simplifies much of the operational workload by automating application deployment, scaling, and maintenance. However, it does not fully eliminate operational tasks. Developers still set scaling parameters, typically involving spinning up additional compute nodes. The most common examples of PaaS are platforms such as Heroku and Elastic Beanstalk.

Containers offer an efficient way to virtualize servers, abstracting the host OS while still requiring active management, scaling, and security. Unlike FaaS, container scaling isn’t automatic and requires additional tooling like Kubernetes or Docker Swarm. Moreover, additional resources like CPU require an additional layer of scaling solutions to add compute nodes to the cluster.

Figure 3. Comparison of cloud architectures

Challenges of serverless

While serverless architecture offers significant benefits, it’s not without its challenges. Understanding these can guide you in making informed decisions about whether serverless is the right fit for your project.

Cold Starts

Functions in serverless architectures are event-driven. When a request triggers a function that isn’t already running, the function has to start up, a process known as a cold start. This startup time can be extremely slow, depending on code complexity and the FaaS provider’s infrastructure. However, subsequent requests will be served immediately and are called as warm starts. Cold starts are a notable drawback for latency-sensitive applications.

For example, AWS Lambda will start our application when traffic comes in and terminate it after some time, regardless of traffic, to maintain fairness between customers. This results in an occasional cold start regardless of whether our functions are warm.

Certain strategies exist to alleviate the pain of cold starts, like choosing platforms with faster runtime. For instance, Java is much slower than Python in bootstrapping the application due to the nature of the JVM overhead, while Python is interpreted and can start execution right away. Also, you can consider options like warming up the functions and using provisioned concurrency to have a few functions always available. Despite these measures, cold starts remain a trade-off in serverless environments.

Statelessness

Serverless functions typically face limitations with local state storage. While local storage like RAM and local disk are available, there’s no guarantee they persist across invocations because the cloud provider can take down our function anytime. This constraint poses challenges for strategies like in-memory caching, as the sporadic nature of function execution reduces cache hit rates and necessitates frequent recomputation.

To address this, we need to externalize state management. For caching, we should utilize out-of-process cache systems like Redis or Memcached, and for persistent data, we should rely on database servers. While these external solutions introduce additional complexity and latency, they are essential for effective serverless design.

Limited Execution

Serverless functions are subject to execution time limits. AWS Lambda, for example, caps execution at 15 minutes per request. After this, the function is forcibly terminated, resulting in a timeout error. This limitation makes serverless unsuitable for long-running processes, requiring alternative architectural approaches for such scenarios.

Vendor Lock-in

Serverless functions are often deeply integrated with their cloud provider’s infrastructure, leading to vendor lock-in. Migrating to a different provider involves adapting operational tools, potentially altering code, and moving dependent infrastructure, such as message buses and monitoring systems. Tooling like the Serverless Framework can ease some of these challenges, but the dependency on provider-specific services remains a significant consideration.

Figure 4. Serverless challenges

Serverless Use Cases

Serverless architecture offers tremendous benefits in terms of scalability, cost efficiency, and reduced operational workload. Yet, its true attractiveness lies in the myriad use cases and applications it enables, all while capitalizing on these benefits.

Some notable examples of what can be built with serverless technology include:

  • Event-driven applications
  • Microservices architectures
  • HTTP endpoints for web applications
  • Data processing and transformation, within the constraints of function execution limits
  • Automation of scheduled tasks
  • Running machine learning inference models

Conclusion

As we’ve explored the world of serverless computing, it’s become evident that serverless is more than just another model for architecting and building software; it represents a revolutionary approach. In recent years, containerized solutions and IaaS using virtual servers like EC2 have dominated infrastructure modeling. Serverless computing now offers a more compelling and innovative alternative.

Serverless brings numerous benefits that can significantly conserve resources for companies. It enables automatic scalability to meet increasing demands and cost savings by eliminating resource wastage and allows engineering teams to focus on what truly matters: business development.

However, it’s crucial to recognize serverless computing's limitations. When designing serverless solutions, considerations like cold starts, statelessness, and vendor lock-in should not be overlooked.

Remember, in the fast-paced business world, time-to-market and agility are key. Developing the best product isn’t enough if it can’t be delivered swiftly. Focusing on core business priorities and automating the rest is crucial to staying ahead of the competition.

About Me — Let’s Connect

Nadar Alpenidze

Hi, and thank you for reading! I’m Nadar Alpenidze, a software developer at AWS. With a passion for knowledge sharing and improving others, I am committed to helping fellow developers grow and excel in their fields. Feel free to connect with me on LinkedIn — I welcome your questions, insights, or even a casual chat about all things software development. Let’s build a vibrant community together!

--

--

Nadar Alpenidze

Software engineer at AWS. 💡My mission is to help you expand your knowledge and become a more exceptional engineer. https://www.linkedin.com/in/nadar-alpenidze