{"id":21955,"date":"2018-05-21T11:39:03","date_gmt":"2018-05-21T18:39:03","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/aspnet\/?p=21955"},"modified":"2018-05-21T11:39:03","modified_gmt":"2018-05-21T18:39:03","slug":"a-penny-saved-is-a-ton-of-serverless-compute-earned","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/dotnet\/a-penny-saved-is-a-ton-of-serverless-compute-earned\/","title":{"rendered":"A Penny Saved is a Ton of Serverless Compute Earned"},"content":{"rendered":"<p>Scott Guthrie recently shared one of my favorite anecdotes on his <a target=\"_blank\" href=\"https:\/\/aka.ms\/red-shirt-2\" rel=\"noopener\">Azure Red Shirt Tour<\/a>. A Microsoft customer regularly invokes 1 billion (yes, that\u2019s with a \u201cB\u201d) <a target=\"_blank\" href=\"https:\/\/aka.ms\/Svbmkh\" rel=\"noopener\">Azure Functions<\/a> per day. The customer reached out to support after the first month thinking there was a bug in the billing system, only to find out that the $72 was in fact correct. How is that possible? Azure Functions is a serverless compute platform that allows you to focus on code that only executes when triggered by events, and you only pay for CPU time and memory used during execution (versus a traditional web server where you are paying a fee even if your app is idle). This is called micro-billing, and is one key reason serverless computing is so powerful.<\/p>\n<blockquote>\n<p>Curious about Azure Functions? Follow the link <a target=\"_blank\" href=\"https:\/\/aka.ms\/go-funcs\" rel=\"noopener\">https:\/\/aka.ms\/go-funcs<\/a> to get up and running with your first function in minutes. <figure id=\"attachment_13925\" aria-labelledby=\"figcaption_attachment_13925\" class=\"wp-caption alignnone\" ><img decoding=\"async\" src=\"https:\/\/msdnshared.blob.core.windows.net\/media\/2018\/05\/redshirt.png\" alt=\"Scott Guthrie Red Shirt\" width=\"1024\" height=\"528\" class=\"size-full wp-image-13925\" srcset=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2018\/05\/redshirt.png 1024w, https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2018\/05\/redshirt-300x155.png 300w, https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2018\/05\/redshirt-768x396.png 768w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><figcaption id=\"figcaption_attachment_13925\" class=\"wp-caption-text\">]<a href=\"https:\/\/msdnshared.blob.core.windows.net\/media\/2018\/05\/redshirt.png\">1<\/a> Scott Guthrie on the Azure Red Shirt Tour<\/figcaption><\/figure><\/p>\n<\/blockquote>\n<p>In fact, micro-billing is so important, it&#8217;s one of three rules I use to verify if a service is serverless. There is not an official set of rules and there is no standard for serverless. The closest thing to a standard is the whitepaper published by the Cloud Native Computing Foundation titled <a target=\"_blank\" href=\"https:\/\/github.com\/cncf\/wg-serverless\/blob\/master\/whitepaper\/cncf_serverless_whitepaper_v1.0.pdf\" rel=\"noopener\">CNCF WG-Serverless Whitepaper v1.0 (PDF)<\/a>. The paper describes serverless computing as &#8220;building and running applications that do not require server management.&#8221; The paper continues to state they are &#8220;executed, scaled, and billed in response to the exact demand needed at the moment.&#8221;<\/p>\n<p>It&#8217;s easy to label almost everything serverless, but there is a difference between <em>managed<\/em> and <em>serverless<\/em>. A managed service takes care of responsibilities for you, such as standing up a website or hosting a <a target=\"_blank\" href=\"https:\/\/aka.ms\/Mkac0u\" rel=\"noopener\">Docker container<\/a>. Serverless is a managed service but requires a bit more. Here is <strong>Jeremy&#8217;s Serverless Rules<\/strong>.<\/p>\n<ol>\n<li><strong>The service should be capable of running entirely in the cloud.<\/strong> Running locally is fine and often preferred for developing, testing, and debugging, but ultimately it should end up in the cloud.<\/li>\n<li><strong>You don&#8217;t have to configure a virtual machine or cluster.<\/strong> Docker is great, but containers require a Docker host to run. That host typically means setting up a VM and, for resiliency and scale, using an orchestrator like Kubernetes to scale the solution. There are also services like <a target=\"_blank\" href=\"https:\/\/aka.ms\/A5rd3p\" rel=\"noopener\">Azure Web Apps<\/a> that provide a fully managed experience for running web apps and containers, but I don\u2019t consider them serverless because they break the next rule.<\/li>\n<li><strong>You only pay for active invocations and never for idle time.<\/strong> This rule is important, and the essence of micro-billing. ACI is a great way to run a container, but I pay for it even when it&#8217;s not being used. A function, on the other hand, only bills when it&#8217;s called.<\/li>\n<\/ol>\n<p>These rules are why I stopped calling managed databases &#8220;serverless.&#8221; So, what, then, does qualify as serverless?<\/p>\n<p>The Azure serverless platform includes Azure Functions, <a target=\"_blank\" href=\"https:\/\/aka.ms\/Dhm1zp\" rel=\"noopener\">Logic Apps<\/a>, and <a target=\"_blank\" href=\"https:\/\/aka.ms\/Ot05o4\" rel=\"noopener\">Event Grid<\/a>. In this post, we&#8217;ll take a closer look at Azure Functions.<\/p>\n<h2>Azure Functions<\/h2>\n<p>Azure Functions allows you to write code that is executed based on an event, or <em>trigger<\/em>. Triggers may include an HTTP request, a timer, a message in a queue, or any other number of important events. The code is passed details of the trigger but can also access bindings that make it easier to connect to resources like databases and storage. The serverless Azure Functions model is based on two parameters: <em>invocations<\/em> and <em>gigabyte seconds<\/em>.<\/p>\n<p>Invocations are the number of times the function is invoked based on its trigger. Gigabyte seconds is a function of memory usage. Image a graph that shows time on the x-axis and memory consumption on the y-axis. Plot the memory usage of your function over time. Gigabyte seconds represent the area under the curve.<\/p>\n<p>Let&#8217;s assume you have a microservice that is called every minute and takes one second to scan and aggregate data. It uses a steady 128 megabytes of memory during the run. Using the <a target=\"_blank\" href=\"https:\/\/aka.ms\/Ijlemq\" rel=\"noopener\">Azure Pricing Calculator<\/a>, you&#8217;ll find that the cost is free. That&#8217;s because the first 400,000 Gigabyte seconds and 1 million invocations are free every month. Running every second (there are 2,628,000 seconds in a month) with double memory (256 megabytes), the entire monthly cost is estimated at $4.51.<\/p>\n<p><figure id=\"attachment_13935\" aria-labelledby=\"figcaption_attachment_13935\" class=\"wp-caption alignnone\" ><img decoding=\"async\" src=\"https:\/\/msdnshared.blob.core.windows.net\/media\/2018\/05\/functions.png\" alt=\"Azure Functions pricing\" width=\"1024\" height=\"725\" class=\"size-full wp-image-13935\" srcset=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2018\/05\/functions.png 1024w, https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2018\/05\/functions-300x212.png 300w, https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2018\/05\/functions-768x544.png 768w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><figcaption id=\"figcaption_attachment_13935\" class=\"wp-caption-text\">]<a href=\"https:\/\/msdnshared.blob.core.windows.net\/media\/2018\/05\/functions.png\">2<\/a> Pricing calculator for Azure Functions<\/figcaption><\/figure><\/p>\n<p>Recently I <a target=\"_blank\" href=\"https:\/\/twitter.com\/jeremylikness\/status\/957976243634307073\" rel=\"noopener\">tweeted about my own experience<\/a> with serverless cost (or lack thereof). I wrote a link-shortening tool. It uses a function to take long URLs and turn them into a shorter code I can easily share. I also have a function that takes the short code and performs the redirect, then stores the data in a queue. Another microservice processes items in the queue and stores metadata that I can analyze for later. I have tens of thousands of invocations per month and my total cost is less than a dollar.<\/p>\n<p><figure id=\"attachment_13945\" aria-labelledby=\"figcaption_attachment_13945\" class=\"wp-caption alignnone\" ><img decoding=\"async\" src=\"https:\/\/msdnshared.blob.core.windows.net\/media\/2018\/05\/linkshortener.png\" alt=\"Link shortener stats\" width=\"1041\" height=\"622\" class=\"size-full wp-image-13945\" srcset=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2018\/05\/linkshortener.png 1041w, https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2018\/05\/linkshortener-300x179.png 300w, https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2018\/05\/linkshortener-1024x612.png 1024w, https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2018\/05\/linkshortener-768x459.png 768w\" sizes=\"(max-width: 1041px) 100vw, 1041px\" \/><figcaption id=\"figcaption_attachment_13945\" class=\"wp-caption-text\">]<a href=\"https:\/\/msdnshared.blob.core.windows.net\/media\/2018\/05\/linkshortener.png\">3<\/a> A tweet about cost of running serverless code in Azure<\/figcaption><\/figure><\/p>\n<p>Do I have your attention?<\/p>\n<p>In future posts I will explore the cost model for Logic Apps and Event Grid. In the meantime&#8230;<\/p>\n<blockquote>\n<p>Learn about and get started with your first Azure Function by following this link: <a href=\"https:\/\/aka.ms\/go-funcs\">https:\/\/aka.ms\/go-funcs<\/a><\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>Scott Guthrie recently shared one of my favorite anecdotes on his Azure Red Shirt Tour. A Microsoft customer regularly invokes 1 billion (yes, that\u2019s with a \u201cB\u201d) Azure Functions per day. The customer reached out to support after the first month thinking there was a bug in the billing system, only to find out that [&hellip;]<\/p>\n","protected":false},"author":404,"featured_media":58792,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[197,327],"tags":[4,37,7537,7539,7565],"class_list":["post-21955","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-aspnet","category-azure","tag-net","tag-azure","tag-azure-functions","tag-cloud","tag-serverless"],"acf":[],"blog_post_summary":"<p>Scott Guthrie recently shared one of my favorite anecdotes on his Azure Red Shirt Tour. A Microsoft customer regularly invokes 1 billion (yes, that\u2019s with a \u201cB\u201d) Azure Functions per day. The customer reached out to support after the first month thinking there was a bug in the billing system, only to find out that [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/21955","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/users\/404"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/comments?post=21955"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/21955\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media\/58792"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media?parent=21955"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/categories?post=21955"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/tags?post=21955"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}