What Is Serverless Architecture and When Should You Use It?
Tags: serverless
Published: 2020-04-07 14:30:15

<p>Cloud computing is constantly evolving, from bare-metal to container technologies. The latest trend in this process is the serverless (Function as a Service, or FaaS) computing model. According to <a href="https://techbeacon.com/enterprise-it/state-serverless-6-trends-watch">Techbeacon</a>, serverless has an annual growth rate of 75%, making it the fastest growing cloud service model. So, serverless architecture isn't a mere buzzword. More companies than ever are adopting it.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>If you're not sure what serverless architecture is, you've come to the right place. Read on to learn what serverless architecture is, when it makes sense, and when it doesn't.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":5452} -->
<figure class="wp-block-image"><img src="https://library.scalyr.com/2019/09/30155102/Building-with-scalyr-implying-serverless-architecture.png" alt="Building with scalyr implying serverless architecture" class="wp-image-5452"/></figure>
<!-- /wp:image -->

<!-- wp:more -->
<!--more-->
<!-- /wp:more -->

<!-- wp:heading -->
<h2>What Is Serverless Architecture?</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>The term <em>serverless architecture</em> can be confusing. It doesn't mean application designs that allow for running applications in some magical space where servers are nonexistent.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><a href="https://martinfowler.com/articles/serverless.html">Serverless architectures</a> are application designs that make use of third-party services (Back end as a Service, or BaaS). They may use custom code run in managed, ephemeral containers on a FaaS platform.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Servers still run your application. But a third-party company takes care of the grunt work of provisioning, managing, and scaling servers. In serverless architecture, you manage and provision nothing.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Serverless architecture often incorporates two components: <a href="https://www.scalyr.com/blog/function-as-a-service-faas/">Function as a Service</a> and Backend as a Service.</p>
<!-- /wp:paragraph -->

<!-- wp:list -->
<ul><li>FaaS is a computing service that allows you to run self-contained code snippets called functions in the cloud. Your functions remain dormant until events trigger them. Functions are self-contained, small, short-lived, and single-purpose. They die after execution.</li><li>BaaS is a cloud computing service that completely abstracts backend logic, which takes place on faraway servers. It allows developers to focus on front-end code and integrate with back-end logic that someone else has implemented. BaaS could be authentication, storage services, geolocation services, user management, and so on.</li></ul>
<!-- /wp:list -->

<!-- wp:image {"id":5443,"align":"center"} -->
<div class="wp-block-image"><figure class="aligncenter"><img src="https://library.scalyr.com/2019/09/26161259/01-serverless-1024x591.png" alt="" class="wp-image-5443"/></figure></div>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>In serverless architecture, you focus on writing code only. You deploy when you’re ready, without caring about what runs it or how it runs.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Is serverless the same as Platform as a Service?</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>Serverless and Platform as a Service (PaaS): What's the Difference?</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Many people mistake Platform as a Service (PaaS) for serverless architecture. Although they are similar in many ways, they aren't the same.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>PaaS providers offer software and hardware infrastructure as a platform to users—what many people call a solution stack. That means you can run custom applications using the provider's platform. Serverless, on the other hand, provides an environment where you can write and run custom code (functions) without managing, provisioning, or scaling infrastructure.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>What do Paas and serverless architecture have in common? You don't manage infrastructure in either one. The platform provider takes care of that. However, differences exist in how you compose your application and how you scale it.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3><strong>Composition</strong></h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>In the PaaS model, you write your application using a framework or language that your platform provider supports, and you deploy your business logic as a single unit. In the serverless model, your business logic is broken down into self-contained units that each perform a business function.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3><strong>Scaling</strong></h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Scaling isn't automatic for PaaS applications. Instead, you have to configure your app and add resources to handle more requests. In serverless architecture, on the other hand, your app scales automatically as the workload increases.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3><strong>Lifetime Availability</strong></h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Like traditional applications, PaaS applications have to be available at all times to continue to serve requests. In serverless, by contrast, functions are short-lived—they die after execution.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Now you understand that PaaS isn't serverless, though the two systems are similar in some ways. But why would you want to go serverless?</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>Why Use Serverless Architecture?</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>As you ponder this question, consider these three key attributes of serverless architecture.</p>
<!-- /wp:paragraph -->

<!-- wp:list -->
<ul><li><strong>It's scalable and highly available. </strong>Scaling traditional applications requires you to understand your traffic pattern. You estimate how much of each resource you'd need, and then you'd provision accordingly. Users troop in from all geographical regions to use modern applications. A traditional application could be overwhelmed by a spike—probably on a black Friday. In serverless, your application is highly available, and it scales automatically as your users grow and usage increases.</li><li><strong>It costs less. </strong>One of the reasons serverless architecture is gaining popularity among startups is because of its pricing model. The cost of running servers 24/7 and paying for idle time is no longer an issue in serverless. You pay for usage only. Functions have allocated time in which they run and die afterward. The provider charges based on the number of executions and the size of memory your workload uses. This helps you optimize costs.</li><li><strong>The time to market is faster. </strong>Operational tasks such as server provisioning, maintenance, and monitoring infrastructure are off your shoulders. You can focus solely on your business logic (code), experiment with ideas, and hit production on time.</li></ul>
<!-- /wp:list -->

<!-- wp:image {"id":5444,"align":"center"} -->
<div class="wp-block-image"><figure class="aligncenter"><img src="https://library.scalyr.com/2019/09/26162205/01-pull-quote-serverless-arch.png" alt="" class="wp-image-5444"/></figure></div>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>With all the promises of serverless, is it perfect for all use cases? No. In some cases, serverless architecture makes sense, but in others, it might not. We'll discuss this point in detail later on in this post.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Let's explore some common use cases of serverless architecture.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>Serverless Architecture Use Cases</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>In a traditional application, your application runs actively on servers. Since your servers are on 24/7, you also pay for idle time. In the serverless world, though, there are no servers to pay for. You only pay per trigger. In other words, you pay for what you use.<br>This advantage makes serverless architecture a good option for business cases that don't have to be always on. In this way, you save money from not paying for idle time.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>In a traditional application, your application runs actively on servers. Since your servers are on 24/7, you also pay for idle time. In the serverless world, though, there are no servers to pay for. You only pay per trigger. In other words, you pay for what you use.<br>This advantage makes serverless architecture a good option for business cases that don't have to be always on. In this way, you save money from not paying for idle time.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Examples of serverless architecture use cases are:</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3>High-Traffic Websites</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>If you're still serving your static websites from an <a href="https://aws.amazon.com/ec2">EC2 instance,</a> you may be missing out on a lot. With serverless, you can host your static website on S3 bucket and serve your assets with a global, fast cloud delivery network. Not only is it cheaper and fast, but it is also highly available and scalable.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3>Multimedia Processing Applications</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>If your business deals with images and videos, then serverless architecture might work well for you. You can use a scalable storage service such as <a href="https://aws.amazon.com/s3/">AWS S3</a> to store your data. An upload event can trigger a lambda function after each successful upload that processes your file asynchronously. Your users can continue to enjoy your app while a highly available and scalable back-end service processes the upload in a non-blocking way.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3>Mobile Backends</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>An API gateway gives you an entry point to your business functions. These functions can be exposed as rest API that your mobile app consumes. Serverless services such as <a href="https://aws.amazon.com/appsync/">AWS AppSync</a> allow you to securely access, manipulate, and combine data from multiple sources in real time.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":5445,"align":"center"} -->
<div class="wp-block-image"><figure class="aligncenter"><img src="https://library.scalyr.com/2019/09/26162546/02-pull-quote-serverless-arch.png" alt="" class="wp-image-5445"/></figure></div>
<!-- /wp:image -->

<!-- wp:heading {"level":3} -->
<h3>Internet of Things (IoT)</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>IoT devices generate a lot of data from their environments through sensors. Organizations often struggle to process this overwhelming data coming from these connected devices in a scalable way. Using a serverless back end like <a href="https://aws.amazon.com/iot-core/" target="_blank" rel="noreferrer noopener">AWS IoT Core</a>, you can scale to billions of devices and trillions of messages.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3>Big Data Applications</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Before cloud computing, the insights big data provided were available only to big enterprises because organizations needed the infrastructures' overheads to make sense of that data. Setting up and maintaining infrastructures for big data isn't easy. With serverless computing, your app can now take advantage of several services, including <a href="https://aws.amazon.com/s3/">Amazon S3</a>, <a href="https://aws.amazon.com/athena/">Amazon Athena</a>, <a href="https://aws.amazon.com/kinesis/">Amazon Kinesis</a>, <a href="https://aws.amazon.com/glue">AWS Glue</a>, and <a href="https://aws.amazon.com/lambda">AWS Lambda</a> to build scalable data pipelines.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Earlier, I mentioned that serverless architecture isn't a silver bullet. There are cases where serverless might not be a good fit.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>When Going Serverless Might Not Make Sense</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>With all the promises of serverless architecture, it has its drawbacks and limitations too. It's important to keep these in mind when considering serverless architecture and plan accordingly.</p>
<!-- /wp:paragraph -->

<!-- wp:list {"ordered":true} -->
<ol><li>There's a limit to how long a function can run. This makes serverless architecture unsuitable for tasks that run for hours.</li><li>What if you require a fast response with a consistent latency of less than 50 milliseconds? Serverless architecture suffers from the problem of <a rel="noreferrer noopener" href="https://mikhail.io/serverless/coldstarts/define/" target="_blank">a cold start</a>. In a case like this, you might need to reconsider your options.</li><li>You may be afraid of vendor lock-in. Serverless architecture could tie you to a single vendor. Migrating serverless applications from one vendor to another requires a lot of manual effort and major changes in your code.</li><li>&nbsp;Serverless vendors limit how much memory you can assign to functions. If you require a complex compute with high memory requirements, then going serverless might not be a good use case.</li><li>&nbsp;Serverless vendors enforce hard limits on deployment size. This could vary from one vendor to another. For example, AWS allows a code deployment size up to <a href="https://docs.aws.amazon.com/lambda/latest/dg/limits.html">250MB</a>. For large code deployment, serverless architecture might not be suitable.</li><li>Serverless is still relatively young. For this reason, <a rel="noreferrer noopener" href="https://www.scalyr.com/blog/observability-production-systems-why-how/" target="_blank">observability</a> is still a problem. Having 360-degree insights into your functions can be difficult.</li></ol>
<!-- /wp:list -->

<!-- wp:heading -->
<h2>Conclusion</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Before moving to serverless architecture, you must first evaluate your use cases. It's critical to understand what your business requirements are and whether serverless architecture would make sense for your project and some of the limitations you'd hit down the road. When you have this information, you can better prepare.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>In this post, we've seen the advantages of serverless architecture. We also discussed some of the drawbacks of serverless architecture and some typical serverless use cases. To build on this knowledge, I encourage you to read these sources:</p>
<!-- /wp:paragraph -->

<!-- wp:list -->
<ul><li><a href="https://aws.amazon.com/blogs/architecture/ten-things-serverless-architects-should-know/">Ten things serverless architects should know</a></li><li><a href="https://www.scalyr.com/blog/aws-lambda-use-cases/">AWS Lambda use cases: 7 reasons Devs should use Lambda</a></li><li><a href="https://www.scalyr.com/blog/how-serverless-will-change-devops/">How serverless will change DevOps</a></li></ul>
<!-- /wp:list -->