Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Exploring Serverless Options for .NET in Azure,...

Exploring Serverless Options for .NET in Azure, AWS, and Beyond

Spencer Schneidenbach

August 28, 2023
Tweet

More Decks by Spencer Schneidenbach

Other Decks in Programming

Transcript

  1. https://www.cloud fl are.com/learning/serverless/what-is-serverless/ Serverless computing is a method of providing

    backend services on an as-used basis. Servers are still used, but a company that gets backend services from a serverless vendor is charged based on usage, not a fi xed amount of bandwidth or number of servers.
  2. The three major cloud providers 0 10 20 30 40

    https://www.statista.com/chart/18819/worldwide-market-share-of-leading-cloud-infrastructure-service-providers/ % Marketshare ?
  3. The three major cloud providers 0 10 20 30 40

    https://www.statista.com/chart/18819/worldwide-market-share-of-leading-cloud-infrastructure-service-providers/ % Marketshare
  4. The three major cloud providers 0 10 20 30 40

    https://www.statista.com/chart/18819/worldwide-market-share-of-leading-cloud-infrastructure-service-providers/ % Marketshare
  5. My experience • 90% of what I do is in

    Microsoft Azure. • I have used Azure and AWS in production. Worked on entire serverless platforms in both Azure and AWS. • My big bias: delivery > perfection.
  6. What this talk is • Good general overview and walkthrough

    of my experience • De fi nitely developer-centric, with lots of architect-y opinions • Discussion on the two major serverless options: • “Turnkey” functions • Container hosting models
  7. What this talk ISN’T • A so-called “expert” preaching you

    about “the right way” • A recommendation on any particular cloud provider for .NET • Dogmatic • You may disagree with some things I say • I also cannot know everything
  8. What we will cover • In some depth • Azure

    Functions/AWS Lambdas/Google Cloud Functions • Azure Container Functions/AWS App Runner/AWS Fargate/Google Cloud Run • By mention only • Azure App Service/AWS Elastic Beanstalk/Google App Engine • Kubernetes stu f
  9. For each thing we will discuss • Development experience •

    Tooling - Visual Studio, Rider, .NET CLI, AWS CLI, GCloud CLI • Deployment • Monitoring • Maturing past “basic” functions • Nuance! (Or as much as I could add in)
  10. Testing methodology • Started with a brand new cloud account

    for each provider • Used the following tools • Visual Studio • Rider • dotnet CLI • AWS CLI • Google Cloud CLI
  11. Really basic things • Deploy a function with a contrived

    error condition • Run it 100 times • See what happens!
  12. Lessons learned • More nuance than I expected • Clouds

    have strengths and weaknesses • There’s friction everywhere - the question is, what friction is tolerable to you and your team?
  13. Azure Functions • Simple requests (HTTP, Event Grid, etc) •

    Great for event-based architectures and small bits of code
  14. Azure Monitor/Application Insights • Comprehensive goodness out of the box

    • Comparatively expensive • …honestly I prefer third party vendors like DataDog
  15. Two execution paths for Azure Functions • In process -

    Azure Functions that execute inside of the Functions host process • Isolated - runs inside a worker process https://learn.microsoft.com/en-us/azure/azure-functions/dotnet-isolated-in-process-di ff erences
  16. In process vs isolated Feature/behavior In-process Isolated worker process Supported

    .NET versions Long Term Support (LTS) versions All supported versions + .NET Framework Core packages Microsoft.NET.Sdk.Functions Microsoft.Azure.Functions.Worker Microsoft.Azure.Functions.Worker.Sdk Durable Functions Supported Supported (public preview) HTTP trigger model types HttpRequest / ObjectResult HttpRequestData / HttpResponseData Dependency injection Supported Supported Middleware Not supported Supported Logging ILogger passed to the function ILogger<T> via dependency injection ILogger/ILogger<T> obtained from FunctionContext or via dependency injection Cancellation tokens Supported Supported Cold start times (Baseline) Additionally includes process launch https://learn.microsoft.com/en-us/azure/azure-functions/dotnet-isolated-in-process-di ff erences
  17. Azure Functions (premium) • Can have pre-warmed instances, preventing cold

    starts • Minimum spend required, though https://learn.microsoft.com/en-us/azure/azure-functions/functions-premium-plan?tabs=portal
  18. Azure Container Apps • Best of all possible worlds as

    you scale - more fl exible hosting option with less spend required during idle periods
  19. https://endjin.com/blog/2022/09/bye-bye-azure-functions-hello-azure-container-apps-part-1-introduction Like Azure Functions, ACA pricing is consumption-based and you

    have the option for your containers to scale down to zero if needed. Obviously this wouldn't help with the cold start issues we've covered above, but it's also possible to set a minimum number of replicas for your container, which would have much the same effect as the Premium Functions plan mentioned above. However, there's a potential advantage over the Premium Functions Plan; the notion of containers becoming inactive - meaning they are still provisioned but idle - in which state the cost is significantly lower. Azure Container Apps
  20. Azure Summary • Azure Functions - great for small bits

    of code to respond to events and/or starting out. HTTP APIs as well… if you don’t mind the cold start. • Azure Functions Premium - great “next level” destination for Azure Functions if you need to help eliminate cold starts, but more expensive (obv) • This article describes spinning this up temporarily when anticipating tra ffi c spikes, then spinning it back down to normal Consumption after the work is done. (Example: https:// www.davepaquette.com/archive/2020/05/23/scaling-azure-functions-from-consumption- plan-to-premium-hosting-plan.aspx) • Azure Container Apps - gives more fl exibility for building scalable apps • Azure App Service - I use these for more general purpose web app hosting, especially if I need predictable pricing and easy, fl exible scale up, easy web con fi guration, etc. https://learn.microsoft.com/en-us/azure/azure-functions/functions-scale
  21. AWS

  22. Serverless options in AWS • AWS Lambda/AWS Serverless Lambdas •

    AWS App Runner/Fargate • AWS Elastic Beanstalk
  23. IAS

  24. IAS

  25. IAS

  26. Other hosted services • AWS Elastic Beanstalk • Like Azure

    App Service, but I have not heard anyone say a positive thing about it • AWS Fargate/App Runner/Elastic Kubernetes Service
  27. AWS Summary • Lambdas - similar to Azure Functions in

    pretty much every way • AWS Serverless Application using Lambdas - almost certainly the direction I would go • AWS App Runner - akin to Container Apps • AWS Fargate - lower level than App Runner • Great article about nuanced di ff erences btwn Fargate and App Runner: https://cloudonaut.io/fargate-vs-apprunner/ • AWS Elastic Beanstalk… kind of like App Service but apparently it’s way worse?
  28. “Honorable” mentions? • Provisioned concurrency • Do The “Jeremy” •

    Jeremy sez: he uses Serverless framework (https://www.serverless.com/) and aws-vault for dev work.
  29. Nitpicky at best • Does not support .NET Framework •

    Not as widely adopted as the other cloud providers, duh
  30. GCS Summary • Cloud Functions - similar to Azure Functions

    and Lambdas in pretty much every way • Cloud Run - managed container system akin to Azure Container Apps/AWS App Runner • App Engine - generalized app hosting akin to App Service • Detailed cost comparison of Functions vs Run • https://medium.com/google-cloud/cloud-run-vs-cloud-functions-whats- the-lowest-cost-728d59345a2e
  31. Initial Thoughts • Most of your cloud providers are going

    to have been chosen already • Your architecture should only be as complicated as it needs to be • Bias getting stu ff done > overthinking what scale you think you MIGHT need • Cloud costs are easy to lose control of - ensure you’re monitoring well. • https://www.troyhunt.com/how-i-got-pwned-by-my-cloud-costs/
  32. General suggestions • Azure Functions/AWS Lambdas/Google Functions for simple slices

    of functionality, especially when cold starts aren’t super critical. • LOVE it for event-driven stu ff . • All cloud providers have a way of “promoting” functions, mainly to eliminate cold starts and manage costs/resources better. You will probably know when you feel you need to do this. • Spencer’s case study
  33. @schneidenbach Azure AWS Google Basic Functions Azure Functions AWS Lambda/AWS

    Lambda Serverless Cloud Functions "Premium" Functions Azure Functions Premium Provisioned Concurrency* Cloud Run Minimum instances* Container abstractions Azure Container Apps AWS AppRunner Cloud Run Lower-level container abstractions Azure Container Instances AWS Fargate Cloud Run I guess? K8S aka The Big Time Azure Kubernetes Service Amazon EKS (Elastic K8S Service) Google Kubernetes Engine General App Host App Service Elastic Beanstalk App Engine * mainly good for eliminating cold starts and is pricey for what it is