Why you should learn and adopt Serverless in 2022 Consider these statistics on the state of Serverless as of May 2021: Lambda functions invocation is more often than two years ago 3.5 times At least organizations is using on cloud 1 in 5 FaaS of developers use as a deployment target, higher than bare-metal servers and PaaS 48% FaaS CloudFront users has embraced Serverless edge computing 1 in 4 History of Web-App Deployment Traditionally web-apps would be deployed on a on-premise or provided by a hosting service. This server would be a physical machine running a web server like Apache, NGINX, etc. on which the web-app would be deployed. bare-metal server Then came Cloud 1.0, which allowed us to move our workloads to cloud providers’ data centers. This meant deploying our web-app on provided by the cloud service. VMs Cloud 2.0, introduced the deployment of containerized web-apps on the cloud. and made this possible. Containers container orchestrators What is Serverless? refers to the concept of building and running applications that do not need server management. There’s no need for a traditional always-on server component. Serverless It's categorized into and . BaaS FaaS is a cloud service model in which developers outsource all the behind-the-scenes aspects of a web or mobile application so that they only have to write and maintain the frontend. One of the most popular examples of is the service - a simple storage service. Backend-as-a-Service (BaaS) BaaS AWS S3 is about running backend code without managing your own server systems or your own long-lived server applications. Function-as-a-Service (FaaS) : Serverless computing does not mean that we no longer use servers to host and run code; nor does it mean that operations engineers are no longer required. Rather, it refers to the idea that consumers of serverless computing no longer need to spend time and resources on server provisioning, maintenance, updates, scaling, and capacity planning. Instead, these tasks and capabilities are handled by a serverless platform and are completely abstracted away from the developers and IT/operations teams. As a result, developers focus on writing their applications’ business logic. CNCF Definition Basics of Functions-as-a-Services (FaaS) is a cloud-native platform for short-running, stateless computation, and event-driven applications which scale up and down instantly & automatically and charge for actual usage at a millisecond granularity. FaaS technologies empower organizations to build and run scalable applications in modern, dynamic environments such as public, private, and hybrid clouds. Containers, service meshes, microservices, immutable infrastructure, and declarative APIs exemplify this approach. Cloud-native consumption plan is billed based on per-second resource consumption and executions. Consumption plan pricing includes a monthly free grant of 1 million requests and 400,000 GB-s of resource consumption per month per subscription in pay-as-you-go pricing across all function apps in that subscription. It charges $0.20 per million executions. Azure Functions charges $0.0000206667 for every GB-second and $0.25 per 1M requests AWS Lambda What triggers FaaS execution? Code execution is in response to events. FaaS relies on event-driven programming model. Consider the example of an API Gateway shown in the above diagram. AWS API Gateway provides tools for creating and documenting web APIs. These APIs route HTTP requests to Lambda functions. When the API Gateway service receives an API request, it triggers an event. This event is an API Call, to execute the mapped AWS Lambda function. The Lambda functions create a response based on the request and return it back. Your code and business logic is written in the Lambda function. Platforms Cloud Computing Services The common categories of cloud computing services are as follows: Infrastructure-as-a-Service provides the base infrastructure. For e.g. a Virtual Machine provided by AWS EC2 or Azure VM. Server setup, provisioning, deployment, and management are the user's responsibilities. 1. IaaS Container-as-a-Service provides container-based virtualization. It allows users to organize, deploy, scale, and manage containers on the cloud. Azure Kubernetes Service(AKS) is a fully-managed Kubernetes service. 2. CaaS Platform-as-a-Service is an integrated application development and deployment solution. It allows application developers to focus on their applications. It takes away the complexity of provisioning, configuring, and managing resources. Azure App Services is a PaaS solution for building Web-Apps and APIs. 3. PaaS Function-as-a-Service allows developers to execute functions in response to events. These functions have code encapsulating business logic. Developers don't have to worry about building complex infrastructure. Azure Functions is a FaaS service. 4. FaaS Software-as-a-Service is an on-demand software that is completely managed by the vendor. Office 365 is an example of SaaS. 5. SaaS Azure Services In the image below we can see how the different services from Azure map to different categories of cloud computing services. As we move from IaaS to FaaS, the concern of provisioning and management decreases, and the focus on business logic increases. FaaS Platforms Shown below are some of the popular public cloud and on-premise FaaS platforms. Deployment Target As per the DORA State of DevOps Report 2021 from Google, 48% of the respondents were using FaaS as their deployment target. Which is higher than bare-metal servers and PaaS environments. Pros and Cons of FaaS ✅ Pros Save time and money on managing servers Pay for what you use Increased scalability, security and reliability Improved developer productivity Decreased management responsibilities Convenient integrations ❌ Cons Cold starts Compute time VPC/Network issues Application size Vendor lock-in Complex debugging Cold Starts One or many micro-containers are responsible for serving a function. When a request comes in, the function checks whether there is a container already running to serve. When an idle container is already available, we call it a “warm” container. If there isn’t a container available, the function will spin up a new one and this is what we call a “cold start”. Applications that haven’t been invoked for a while take longer to start up and handle the first request. The image below shows a comparison of typical cold start durations across cloud providers for common languages. The darker ranges are the most common 67% of durations, and lighter ranges include 95%. AWS leads with all languages being well below 1 second. GCP start-up usually takes between 0.5 and 2 seconds. Azure has high startup times often up to 5 seconds. Factors like cloud provider, language, base OS, package size, memory, etc. affect cold starts. When to use FaaS ✅ FaaS is good for: Stateless event-driven tasks Tasks that can be broken into small independent units of work Tasks that have infrequent or unpredictable usage patterns Background work or system to system communication. ❌ FaaS is not good for: Stateful tasks Long-running tasks Computationally intensive Streaming Real-world use-cases 1. BBC website Around half of the BBC’s website is rendered with AWS Lambda. They perform over 100 million serverless function invocations per day. Web rendering - the rendering happens on AWS Lambda. Every second About 2,000 lambdas run every second to create the BBC website Business layer. REST APIs powered by Lambda Platform & Content production are on EC2. Traffic management – NGINX on EC2 instances. 2. LEGO transformation Lego uses 200+ AWS Lambda functions to transform its legacy website. Architecture for an Email notification with signed URL for vouchers. References https://www.datadoghq.com/state-of-serverless/ https://github.com/cncf/wg-serverless/blob/master/whitepapers/serverless-overview/cncf_serverless_whitepaper_v1.0.pdf https://landscape.cncf.io/serverless https://martinfowler.com/articles/serverless.html https://docs.microsoft.com/en-us/azure/architecture/example-scenario/ai/news-feed-ingestion-and-near-real-time-analysis https://speakerdeck.com/danilop/how-lego-dot-com-accelerates-innovation-with-serverless https://speakerdeck.com/danilop/the-serverless-journey-of-shop-dot-lego-dot-com https://docs.microsoft.com/en-us/azure/azure-functions/ https://aws.amazon.com/lambda/ https://www.serverless.com/ https://services.google.com/fh/files/misc/state-of-devops-2021.pdf https://medium.com/bbc-design-engineering/moving-bbc-online-to-the-cloud-afdfb7c072ff https://www.serverlesschats.com/73/ https://mikhail.io/serverless/coldstarts/