Book Image

Hands-On Serverless Computing

By : Kuldeep Chowhan
Book Image

Hands-On Serverless Computing

By: Kuldeep Chowhan

Overview of this book

Serverless applications and architectures are gaining momentum and are increasingly being used by companies of all sizes. Serverless software takes care of many problems that developers face when running systems and servers, such as fault tolerance, centralized logging, horizontal scalability, and deployments. You will learn how to harness serverless technology to rapidly reduce production time and minimize your costs, while still having the freedom to customize your code, without hindering functionality. Upon finishing the book, you will have the knowledge and resources to build your own serverless application hosted in AWS, Microsoft Azure, or Google Cloud Platform, and will have experienced the benefits of event-driven technology for yourself. This hands-on guide dives into the basis of serverless architectures and how to build them using Node.js as a programming language, Visual Studio Code for code editing, and Postman for quickly and securely developing applications without the hassle of configuring and maintaining infrastructure on three public cloud platforms.
Table of Contents (16 chapters)

What is serverless computing?

Serverless applications still require servers to run; hence, the term is a misnomer. Serverless computing adds a layer of abstraction on top of a cloud infrastructure, so developers need not worry about provisioning and managing physical or virtual servers in the cloud. Serverless computing gives you the capability to develop, deploy, and run applications without having to think about provisioning and management of servers. Serverless computing doesn't need you to provision, manage, and scale the infrastructure required to execute your application. The cloud provider automatically provisions the infrastructure required for your function to run and scale your serverless application with high availability.

In most cases, when people think of serverless computing, they are likely to think of applications with backends that run on cloud providers, such as AWS, that are fully managed, are event triggered, and are ephemeral, lasting only for the invocation that runs within a stateless container. While serverless applications are fully managed and hosted by cloud providers, such as AWS, it is a misinterpretation to say that the applications are completely running serverless. Servers are still involved in the execution of these serverless applications; it is just that these are managed by cloud providers, such as AWS. One way to think about these serverless applications is as FaaS. The most popular implementation of FaaS at the moment is AWS Lambda. However, there are other FaaS implementations from Microsoft Azure called Azure Functions, from GCP called Cloud Functions, and from the open source serverless platform from Apache called OpenWhisk.

Serverless computing is all about the modern developer's expanding frame of reference.

What we have seen is that the atomic unit of scale has been changing from the virtual machine to the container, and if you take this one step further, we start to see something called function—a single-purpose block of code. It is something you can analyze very easily. It can:

  • Process an image
  • Transform a piece of data
  • Encode a piece of video

The following diagram depicts the difference between Monolothic, Microservice, and FaaS architectures:

Monolithic versus Microservice versus FaaS

Developing serverless applications means that you can focus on solving the core business problem instead of spending time on how to operate and manage runtimes, or compute infrastructure, either in on-premises, or in the cloud. With this reduced overhead, developers can reclaim the time and energy that they would usually spend on developing solutions to provision, manage, and scale the applications that are highly available and reliable. I will touch upon this more later in the book.

The real goal of the serverless computing movement is to provide a high level of abstraction of the compute infrastructure so that developers can focus on solving critical business problems, deploy them rapidly, and reduce the time it takes for business ideas to be marketed, as opposed to the time it takes if you use traditional infrastructure for your applications.

Serverless and event-driven collision

Event-driven computation is an architecture pattern that emphasizes action in response to or based on the receptions of events. This pattern promotes loosely coupled services and ensures that a function executes only when it is triggered. It also encourages developers to think about the type of events and responses a function needs in order to handle these events before programming the functions:

Event-driven architecture example

A system built with event-driven architecture consists of Event Producers that produce a stream of events that are ingested using Event Ingestion, and then Event Consumers that listen for the events, as shown in the preceding diagram.

Events are delivered to consumers in near real time so that they can respond immediately to the events as they happen. Event producers are decoupled from the event consumers. As they are decoupled, the producers don't know which consumers are listening to the events that they produce. Event consumers are also decoupled from one another, and every event consumer sees every events produced by the event producers.

Serverless applications are usually built by combining multiple functions (FaaS) using offerings, such as AWS Lamdba or Microsoft Azure Functions, together with external backend resources, such as Amazon S3, Amazon DynamoDB, and many more solutions to manage the state between invocations. The architecture that ties these multiple functions (FaaS) is event-driven architecture. By combining tools, such as AWS Lambda and Amazon S3, you can develop applications without having to think about the provision and management of the infrastructure. As this is a shift in architecture compared to how you might have operated so far, you would also need to change how data will flow through your application, which is made up of functions.

In this event-driven architecture, the functions are event consumers because they are expected to come alive when an event occurs and are responsible for processing it. Some examples of events that trigger serverless functions include the following:

  • API requests
  • Scheduled events
  • Events in object storage
  • Events in databases
  • Notification events