Serverless For Dummies
Tags: serverless, beginners, programming
Published: 2021-08-02 03:49:52

<!-- wp:paragraph -->
<p>A couple of days ago I started looking at job vacancies for backend developers.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>I started to notice some sort of pattern.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>They almost all required some sort of experience with cloud providers such as AWS.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>I don't have any such experience, and this was the inspiration behind this article.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>I've scoured the internet for all sorts of information on cloud providers, it turns out there is a common unifying architecture behind all of them.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>It's called Serverless.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><strong>In this article, you will learn:</strong></p>
<!-- /wp:paragraph -->

<!-- wp:list -->
<ul><li>How companies <strong>manage</strong> their <strong>infrastructure</strong> before introducing serverless</li><li>The <strong>core</strong> concepts behind the serverless architecture</li><li>The <strong>benefits</strong> and <strong>drawbacks</strong> of using the serverless architecture</li><li>Common <strong>misconceptions</strong> about serverless</li></ul>
<!-- /wp:list -->

<!-- wp:heading -->
<h2>The History Behind Serverless</h2>
<!-- /wp:heading -->

<!-- wp:image {"align":"center","id":648,"sizeSlug":"full","linkDestination":"none"} -->
<div class="wp-block-image"><figure class="aligncenter size-full"><img src="https://softwareadventuring.com/wp-content/uploads/2021/07/1-8.png" alt="" class="wp-image-648"/></figure></div>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Serverless is the latest evolution of managing software infrastructure.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Every evolution eases the management of infrastructure, making it easier, faster, and cheaper.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Let's go over each of them.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3>Do it All Yourself (D.I.A.Y)</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>In the beginning, if you wanted to publish your software, you had to do all the "<em>grunt</em>" work yourself.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Meaning, you had:</p>
<!-- /wp:paragraph -->

<!-- wp:list {"ordered":true} -->
<ol><li>Buy a server</li><li>Set it up (operating system, firewalls, etc...)</li><li>Copy your code over to the server</li><li>Maintain it</li></ol>
<!-- /wp:list -->

<!-- wp:paragraph -->
<p>This is slow and pretty expensive.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>You had to manually upgrade your servers and fix any hardware issues that come up.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Another big issue with this approach is scalability.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>You have to get additional servers, and your gonna have to deal with load balancing, which may get very frustrating.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>But on the bright side, you have full control of the server and the contents inside it.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3>Virtual Machines</h3>
<!-- /wp:heading -->

<!-- wp:image {"align":"center","id":649,"sizeSlug":"large","linkDestination":"none"} -->
<div class="wp-block-image"><figure class="aligncenter size-large"><img src="https://softwareadventuring.com/wp-content/uploads/2021/07/2-7-1024x818.png" alt="" class="wp-image-649"/></figure></div>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>CPU's nowadays are much faster than they were in the past.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>This advancement has brought a new way to manage infrastructure.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Instead of configuring one workload/program with one physical server, we can have multiple workloads on a single physical server.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>This is made possible by installing a hypervisor such as VMware vSphere or Microsoft Hyper-V. This allows us to support multiple guest operating systems by sharing the host's resources, such as memory and processing.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>In comparison to physical servers, virtual machines are more:</p>
<!-- /wp:paragraph -->

<!-- wp:list -->
<ul><li><strong>Cheaper</strong>: You can have multiple workloads on a single physical machine.</li><li><strong>Efficient</strong>: The hypervisor efficiently distributes resources to virtual machines.</li><li><strong>Scalable</strong>: To scale, you can simply add more virtual machines on a single server.</li></ul>
<!-- /wp:list -->

<!-- wp:paragraph -->
<p>But it's not all sunshine and rainbows, the downside is that it is much more complex to manage virtual machines than it is physical servers.</p>
<!-- /wp:paragraph -->

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

<!-- wp:image {"align":"center","id":650,"width":334,"height":288,"sizeSlug":"large","linkDestination":"none"} -->
<div class="wp-block-image"><figure class="aligncenter size-large is-resized"><img src="https://softwareadventuring.com/wp-content/uploads/2021/07/3-6-1024x887.png" alt="" class="wp-image-650" width="334" height="288"/></figure></div>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Containers are pretty popular nowadays.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>They were mostly popularized due to <a href="https://softwareadventuring.com/introduction-to-docker/">Docker</a>.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Containers are essentially an "<em>upgrade</em>" to virtual machines.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>It jumbles your program, with the <strong>minimum dependencies</strong> needed to run it into a <strong>single unit</strong>.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Instead of booting up a whole operating system for your program, containers <strong>share</strong> the hosts operating system. This makes them very light and fast.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>This is the basics of containers, but if you want a more thorough explanation, check out our post on <a href="https://softwareadventuring.com/introduction-to-docker/">Docker and Containerization</a>.</p>
<!-- /wp:paragraph -->

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

<!-- wp:image {"align":"center","id":651,"sizeSlug":"full","linkDestination":"none"} -->
<div class="wp-block-image"><figure class="aligncenter size-full"><img src="https://softwareadventuring.com/wp-content/uploads/2021/07/4-5.png" alt="" class="wp-image-651"/><figcaption>Source: <a href="https://www.gocd.org/2017/06/26/serverless-architecture-continuous-delivery/"></a><a href="https://www.gocd.org/2017/06/26/serverless-architecture-continuous-delivery/">https://www.gocd.org/2017/06/26/serverless-architecture-continuous-delivery/</a></figcaption></figure></div>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Serverless is the latest addition to infrastructure management.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>It essentially uses a cloud provider (AWS, Azure, or Google Cloud) to completely manage your infrastructure.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>You don't have to worry about servers, scalability, fault tolerance, etc...</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>It's all managed by the cloud provider.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Initially serverless started out as:</p>
<!-- /wp:paragraph -->

<!-- wp:list -->
<ul><li>Backend as a Service (BaaS)</li><li>Function as a Service (FaaS)</li></ul>
<!-- /wp:list -->

<!-- wp:paragraph -->
<p>Let's delve a bit deeper into each</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3>Backend as a Service</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Serverless was first thought of applications that partially or fully use third party cloud provided services to manage server-side logic.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Examples include mobile apps or single pages applications (SPA) that use:</p>
<!-- /wp:paragraph -->

<!-- wp:list -->
<ul><li>Cloud Accessible Database (ex. Firebase, Parse)</li><li>Authentication Services (ex. OAuth, AWS Cognito)</li></ul>
<!-- /wp:list -->

<!-- wp:paragraph -->
<p>These types of services are known as Backend as a Service (BaaS).</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3>Function as a Service</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>The most popular meaning of serverless is Function as a Service (FaaS).</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>This is where application code is still run by the developer but it’s run in stateless compute containers that are event-triggered, ephemeral (may only last for one invocation), and fully managed by a third party.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>The most popular FaaS is AWS Lambda, others include Google Cloud Functions and Azure Functions.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>We usually refer to FaaS when talking about Serverless.</p>
<!-- /wp:paragraph -->

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

<!-- wp:paragraph -->
<p>You might ask me:</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>"why would I use this?"</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>This is a very valid question, and to answer that we will go over the benefits that serverless provides us.</p>
<!-- /wp:paragraph -->

<!-- wp:list -->
<ul><li><strong>Cheap</strong> — In serverless, you only pay for what you use. For example, in a traditional server of 100GB, if you're only using 10GB of the 100GB, you would still pay for the full 100GB. While in serverless you would only pay for what you use. This can be extended to both BaaS and FaaS, it might be cheaper to not implement some features if you can directly use a backend service provided. While for FaaS, the cost benefits come in scaling. Meaning that you only pay when your functions are being run. When they aren't being run, you don't pay a single dime.</li><li><strong>Fast</strong> — When you don't have to worry much about infrastructure, you have the ability to focus most of your energy on development. Essentially making time to market, much faster.</li></ul>
<!-- /wp:list -->

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

<!-- wp:paragraph -->
<p>It's time to face reality.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Nothing is perfect.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>It's time to go over the drawbacks of using serverless:</p>
<!-- /wp:paragraph -->

<!-- wp:list -->
<ul><li><strong>Vendor control</strong> — Your cloud provider controls your whole infrastructure, which may cause issues if they have any problems on their end. Problems such as system downtime, unexpected limits, cost changes, loss of functionality, forced API upgrades, and more.</li><li><strong>Vendor lock-in</strong> — Cloud providers aren't interchangeable, they may have the same services but most likely that they are implemented differently. If you want to move from one provider to another, you will be forced to do some code changes or even architectural changes.</li><li><strong>Complexity</strong> — Things get complex when you have many functions. Complexity may arise in code, architecture, or even simply debugging.</li><li><strong>Testing</strong> — Unit testing functions isn't that hard, because they are stateless and isolated. The difficulty comes when you have to do integration tests between two or more functions.</li></ul>
<!-- /wp:list -->

<!-- wp:heading -->
<h2>Common Misconceptions</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Serverless started in 2015, it's still fairly new, with that comes a lot of misconceptions.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Let's break down the most common misconceptions that people have about serverless.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3>Serverless = No Servers</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Serverless doesn't mean there aren't any servers involved.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Your code must be stored somewhere.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>It just means that you don't have to deal with it anymore.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Serverless = Fewer Servers</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3>Serverless Means Functions as a Service (FaaS)</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Most people think that Serverless are essentially FaaS such as AWS Lambda, but there are many other services that can be considered to be serverless.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Here are the ones provided by AWS:</p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":652,"sizeSlug":"full","linkDestination":"none"} -->
<div class="wp-block-image"><figure class="aligncenter size-full"><img src="https://softwareadventuring.com/wp-content/uploads/2021/07/5-4.png" alt="" class="wp-image-652"/></figure></div>
<!-- /wp:image -->

<!-- wp:heading {"level":3} -->
<h3>Serverless doesn’t perform as well</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Many people say that serverless functions take way too long to start but this happens when you don't properly configure the right memory size for each function.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Some functions simply require more memory and some less. It's up to you to find the right balance.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3>Serverless is super cheap</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>There's this meme going on about huge bills coming from cloud providers.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Sadly it's true, this happens when you just use an absurd amount of services or not optimizing the use of your services.</p>
<!-- /wp:paragraph -->

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

<!-- wp:paragraph -->
<p>Serverless is definitely the future.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>There's no resisting it.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>But you pushed through it, and have gotten the basics of serverless down.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><strong>Today you learned:</strong></p>
<!-- /wp:paragraph -->

<!-- wp:list -->
<ul><li>The history behind serverless</li><li>Core concepts of serverless architecture</li><li>Benefits and drawbacks of serverless</li></ul>
<!-- /wp:list -->